0

After reading several articles about URL rewrite with aspnet on this forum I still have some unanswered questions. I understand the concept but haven't seen examples of functionality I like to have. Hope someone can help me out with:

  1. dynamically add new rules when I add new record in database a new rewrite URL needs to be created. for example a record with name of a city has to redirect request to city.aspx?cityId=1

URL: http://example.com/rotterdam/
shows: http://example.com/city.aspx?cityID=1

what is a good way to save theses rules? (xml file or load in memory) what is best way to handle requests : global.asax or HTTP module?

BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

0

Which version of ASP.net are you targeting?

Version 3.5 and above you can utilise Routing (even with webforms) below that you can't :)

Assuming that you can use routes, you can do the following in the global asax...

protected void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); }

public static void RegisterRoutes(RouteCollection routes) { routes.Add(new Route("/cities/{cityname}",new CityRouteHandler())); }

where cityroutehandler is like the customroutehandler described in the answer here

Friendly URLs for ASP.NET

Community
  • 1
  • 1
Mike Miller
  • 16,195
  • 1
  • 20
  • 27