C# ASP.NET中带数值约束路径的路由

C# ASP.NET中带数值约束路径的路由,c#,asp.net,c#-4.0,url-routing,C#,Asp.net,C# 4.0,Url Routing,我试图将由数值和字符串组成的特定路径路由到特定的aspx页面 我在global.asax.cs文件中初始化了以下路由代码: void Application_Start(object sender, EventArgs e) { // Code that runs on application startup RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.Regi

我试图将由数值和字符串组成的特定路径路由到特定的aspx页面

我在global.asax.cs文件中初始化了以下路由代码:

  void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
    void RegisterRoutes(RouteCollection routes)
    {


        routes.MapPageRoute("",
        "{id}/{name}", "~/item.aspx",
        true,
        new RouteValueDictionary { { "id", @"\d+"} }
        );

    }
我还有一个item.aspx页面

1) 当我尝试使用此url访问页面时:

http://localhost:8895/1/test/
我得到404错误

2) 我还尝试将名称添加到
RouteValueDictionary
中,如下所示:

new RouteValueDictionary { { "id", @"\d+" }, { "name", @"[a-z0-9-]+" } }
3) 在另一次尝试中,我在defaults参数中输入null:

 routes.MapPageRoute("",
        "{id}/{name}", "~/item.aspx",
        true,
        null,
        new RouteValueDictionary { { "id", @"\d+" }, { "name", @"[a-z0-9-]+" } }
        );
但我仍然得到404错误

我正在ASP.NET 4.5/C#/Visual Studio 2013中开发


我做错了什么?

在路由值字典中也定义参数名。@AlbertoLeón我怎么能对任何字符串这样做?@AlbertoLeón我尝试一下,没有任何运气。我用我使用的样本代码更新了问题。谢谢,谢谢。你的问题回答了我的答案。我已经做了你在这里所做的事情,它是有效的。问:你们有多条路线吗?您可以粘贴整个RegisterRoutes方法吗?问题:您能否(多次)验证~/item.aspx是否确实存在?它拼写正确,并且位于网站的根目录中?如果有拼写错误,它将给出404。