2012-07-12 77 views
1

我想通过使用asp.net路由在asp.net webforms中实现无扩展的URL。阻止路由到文件夹在asp.net路由

routes.Add("MyRouting", new Route("{PagePath}", 
new MyRouteHandler("~/Default.aspx"))); 

通过这种扩展名的URL工作正常,但在少数情况下它的发生是路由路径确实存在作为一个真正的物理路径。

EG:localhost/Services抛出404异常,因为在根目录中有一个名为Services的 真实文件夹。

如何跳过目录路由?

感谢

回答

1

下面的代码可能是你需要获得来自于URL的更严密的控制了答案。

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(/.*)?" } 
    ); 
    ... 
}