I am having problems with asp 4.0 routing.
i have methods in Global.cs
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("cats","Categories/{ct}/{catname}","~/catwise.aspx");
}
and
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
and on my master page
<a href="Categories/<%# Eval("Category_Id")%>/<%# Eval("Category_Name")%>">
this is working perfectly in first routing like Categories/1/Apple but now after first routing all the links are double fro routed page like Categories/1/Apple/Categories/2/Banana.
The links are climbing on each other so the page shows Resource not found
i tried setting Base but it made the matters worse.
I am not using any custom handlers
how should i solve this problem?/why is it not working properly?
tried using / before url like <a href="/Categories/<%# Eval("Category_Id")%>/<%# Eval("Category_Name")%>"> but it said resource not found so added / in routes.MapPageRoute("cats","/Categories/{ct}/{catname}","~/catwise.aspx");
but it threw compile time error saying url cannot contan / or ~ or ?.
This is not a Routing issue. The problem is with the link. I don’t know if the is a better way to generate links in Web Pages but a quick fix would be to simply add a
/:EDIT:
When you are in the home page
http://mysite/and the browser see a “relative” link likeCategories/1/Appleit adds that to the current path so the outcome ishttp://mysite/Categories/1/Apple. Because your link is relative to the page, the next time you hit the link the browser adds that again and you havehttp://mysite/Categories/1/Apple/Categories/1/Apple. The quick fix I proposed is about changing your relative link to absolute by adding a leading/.The whole issue has nothing to do with asp.net and its routing. Its about how the browser treats relative links. I think there are more proper ways to generate links (when using routing), like:
In the data binding scenario you can try:
See also here