Reputation: 3067
I am trying to implement extensionless urls in asp.net webforms by using asp.net routing.
routes.Add("MyRouting", new Route("{PagePath}",
new MyRouteHandler("~/Default.aspx")));
By doing this extensionless URL works fine but for a few cases it happend that the routing path actually existed as a real physical path.
EG: localhost/Services throws 404 exception because there is a real folder called Services in the root.
How do I skip the routing of directories?
Thanks
Upvotes: 1
Views: 130
Reputation: 398
The following code might be the answer you need to get a closer control of the URL that comes in.
public static void RegisterRoutes(RouteCollection routes) {
// example: ignore routes with this file extension and with any extra text afterwards
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
...
// example: new route to modify an URL and remove the .aspx extension
routes.MapRoute(
"UrlManagerRoute",
"{*url}",
new { controller = "MyController", action = "MyAction" },
new { url = @".*\.aspx(/.*)?" }
);
...
}
Upvotes: 1