【问题标题】:preventing routing to folders in asp.net routing防止路由到asp.net路由中的文件夹
【发布时间】:2012-07-12 05:56:14
【问题描述】:

我正在尝试通过使用 asp.net 路由在 asp.net 网络表单中实现无扩展名 url。

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

通过执行此无扩展 URL 可以正常工作,但在少数情况下,路由路径实际上作为真实的物理路径存在。

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

如何跳过目录路由?

谢谢

【问题讨论】:

    标签: asp.net routing


    【解决方案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(/.*)?" }
        );
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 2011-06-23
      • 2011-04-04
      • 1970-01-01
      • 2017-02-28
      • 2013-10-17
      • 2011-08-17
      相关资源
      最近更新 更多