使用ASP.NET 4.0进行URL路由无法找到资源错误

时间:2012-07-22 06:58:10

标签: c# url-routing asp.net-webpages

我正在尝试实现简单的页面路由,由于某种原因它无法正常工作。我已经交叉检查了几乎所有东西,但似乎仍然没有任何效果。

我列出了Activities.aspx&上的所有活动。在Activity-Details.aspx页面上显示活动活动的详细信息。

URL路由实现后的Activities.aspx页面上的

链接就像 http://localhost:49442/website/en/activity/en-US/44/31/event-title-will-go-here

当我点击链接时,它总是显示错误消息

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /website/en/activity/en-US/44/31/event-title-will-go-here

我正在开发一个多语种网站,我在 en & ar 下的阿拉伯语和

等文件夹结构
/ 
/en
/en/Activities.aspx
/en/Activity-Details.aspx
...
/ar
/ar/Activities.aspx
/ar/Activity-Details.aspx
...
/images
/css

我有其他项目的URL路由,但在这一个我错过了一些东西。

Global.asax文件的代码

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.Ignore("{resource}.exe/{*pathInfo}");

    routes.MapPageRoute("ActivityRoute", "activity/{Language}/{EventID}/{PageID}/{EventTitle}", "~/en/Activity-Details.aspx", false,
                new RouteValueDictionary {
                    { "Language", "en-US"},
                    { "EventID", "0" },
                    { "PageID", "0"},
                    { "EventTitle", "event-not-found" }},
                new RouteValueDictionary {   
                    {"Language", "[a-z]{2}-[a-z]{2}"},
                    { "EventID", "[0-9]{1,8}" },
                    { "PageID", "[0-9]{1,8}" }
                });
}

的web.config 我是否需要对web.config文件进行任何更改以使url路由正常工作。我在web.config中有以下条目。我删除了它,但它仍然无法正常工作..

  <system.web>
    <httpModules>
      <add name="RoutingModule" type="System.Web.Routing.UrlRoutingModule"/>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>
  </system.web>

我还在using System.Web.Routing页面上添加了Activity-Details.aspx。但我不确定为什么我会一直收到错误。

1 个答案:

答案 0 :(得分:1)

安装并启用Route Debugger。它会告诉你每条路线被击中的原因和原因。

顺便说一句,您没有在您的路线中映射您的网址的这一部分:website / en /