0
votes

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/View/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!

2
You've got "member" and "view" around the wrong way in the URL string pattern of the route that you are mapping compared to the URL you are trying in the browser - Russ Cam
Did you add it to your map before or after your default handler? - Jonathan Bates

2 Answers

2
votes

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