Andrey
Andrey

Reputation: 21285

Asp.net page routing not working

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!

Upvotes: 0

Views: 4504

Answers (2)

Andrey
Andrey

Reputation: 21285

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

Upvotes: 1

Chase Florell
Chase Florell

Reputation: 47377

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

Upvotes: 2

Related Questions