【问题标题】:How to ignore URL routing for subdirectories ASP.NET 4.0如何忽略子目录 ASP.NET 4.0 的 URL 路由
【发布时间】:2012-03-29 08:53:02
【问题描述】:

我正在使用 URL 路由 .NET 4.0 将公司名称路由到他们的页面

www.xyz.com/companyname 效果很好,但如果页面像这样,我不想路由

www.xyz.com/Pages/Company/Products.aspx?id=123 如果网址以 "Pages"

开头,我想忽略
    void RegisterRoutes(RouteCollection routes)
    {
        routes.Ignore("~/Pages/"); // i tried this but did not work

        routes.Ignore("{resource}.axd/{*pathInfo}");
        routes.Ignore("");
        routes.MapPageRoute(
           "Bayi Sayfa",               
           "{*BayiName}",  
           "~/Pages/HomePage/Default.aspx" 
        );
    }

我也试过了

routes.Ignore("Pages/");

但这也行不通

【问题讨论】:

    标签: asp.net url-routing


    【解决方案1】:

    我在忽略其他文件扩展名时发现了问题

       routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" });
       routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" });
    

    那么这条线就可以了

       routes.Add(new Route("Pages", new StopRoutingHandler()));
    

    【讨论】:

    • 我写的 StopRoutingHandler() 没有代码。它是已经定义的函数
    猜你喜欢
    • 2012-04-30
    • 1970-01-01
    • 2010-09-21
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多