开发者

URL routing not working with ASP.NET web forms?

I've recently started a web application and decided to use url routing in it (basically just to get some practice with it).

The app is .NET4, and I'm using VS2010 SP1 and IIS Express (integrated pipeline).

The thing is, when I run the app, routing works fine as long as there's no parameter in the route URL. I开发者_StackOverflow社区f there is a parameter, then I get a 404.

Here's the relevant code from global.asax.cs:

void RegisterRoutes(RouteCollection routes)
{
    routes.Clear();
    routes.MapPageRoute("Users_Edit", "users/view/{username}", "~/users/user_detail.aspx", false);
    routes.MapPageRoute("Users_Create", "users/create", "~/users/user-detail.aspx", false);    
}

void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
}

The app is running on IIS Express from VS. The virtual folder is /cms.

If I go to http://localhost:8888/cms/users/create I see my page as intended.

If I go to http://localhost:8888/cms/users/view/Matt I get a 404 error (from ASP.NET not from IIS, so the request is going into the ASP.NET pipeline).

I've tried adding the following to web.config, but this didn't make any difference:

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

I've tried changing to Classic mode in IIS Express but that made no difference. Neither did using good old Cassini rather than IIS Express.

Any ideas what I'm doing wrong?

Cheers,

Matt


There seems to be a typo the actual page name in the non-working route. You have used page_detail.aspx in this route while in working route, you have used page-detail.aspx - notice the underscore vs hyphen. So I believe fixing that should do the trick i.e.

routes.MapPageRoute("Users_Edit", "users/view/{username}", "~/users/user-detail.aspx", false);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜