开发者

Asp.net page routing not working

开发者 https://www.devze.com 2023-01-16 15:23 出处:网络
I am trying to add page routing (I use regular asp.net 4.0, not mvc), so that when a user goes to: http://sitename.com/public/member/view/andrey

I am trying to add page routing (I use regular asp.net 4.0, not mvc), so that when a user goes to:

http://sitename.com/public/member/view/andrey

they would get to: http://sitename.com/public/memberprofile.aspx?userName=andrey

I added following in Global.asax:

protected void Application_Start(object sender, EventArgs e)
{
    RouteTable.Routes.MapPageRoute("MemberViewRoute",
        "Public/Vie开发者_JS百科w/Member/{username}",
        "~/Public/MemberProfile.aspx");
}

But when I try going to http://sitename.com/public/member/view/andrey in my browser, I get 404

Is there anything else that needs to be done for this routing to work other than adding a page route map?

Thanks!


Your route says Public/View/Member/{username}
But your link is /public/member/view/andrey

This would definitely 404

Why not try and change your route to

protected void Application_Start(object sender, EventArgs e)
{
    RouteTable.Routes.MapPageRoute("MemberViewRoute",
        "Public/Member/View/{username}",
        "~/Public/MemberProfile.aspx");
}

and see what happens


I actually found this great article that helped me fix my problem: http://blogs.msdn.com/b/rjacobs/archive/2010/06/30/system-web-routing-routetable-not-working-with-iis.aspx

0

精彩评论

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