使用数字约束路径在ASP.NET中进行路由

时间:2015-02-01 10:09:06

标签: 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.RegisterBundles(BundleTable.Bundles);
    }
    void RegisterRoutes(RouteCollection routes)
    {


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

    }

我也有一个item.aspx页面。

1)当我尝试使用此网址访问该网页时:

http://localhost:8895/1/test/

我收到 404错误

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

new RouteValueDictionary { { "id", @"\d+" }, { "name", @"[a-z0-9-]+" } }

3)在另一次尝试中,我将null放在defaults参数中:

 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中开发

我做错了什么?

0 个答案:

没有答案
相关问题