0

I have really weird problem with url routing. I defined 3 routes for menu bar like that

routes.MapPageRoute("Article", "Article/{id}/{title}", "~/article.aspx");
routes.MapPageRoute("Contact", "Contact", "~/contact.aspx");            
routes.MapPageRoute("Category","Category/{id}/{name}","~/category.aspx");

when i click to contact i get www.website.com/Contact and then i click to an article i get www.website.com/Article/id/title and all links are working.

However when i click an article firstly and then click contact, i have www.website.com/Article/id/title/contact, or www.website/category/id/name/contact

This problem only occurs when clicking from parameter routes to nonparameter routes. I will be glad if u give any idea. Thank you.

2
  • You've shown us the routing, but not how you're creating the routes in your markup. Commented Apr 6, 2015 at 17:56
  • here my route creating <a href='<%# GetRouteUrl("Article", new { id = Eval("ArticleID") ,title=Eval("ArticleTitle") })%>'> and my nonparameter link in menubar is <a href="Contact">Contact</a> Commented Apr 6, 2015 at 18:02

1 Answer 1

1

Your contact link isn't application root relative. You need to make it application root relative. The easiest way in Web Forms is to switch to use a control instead of plain anchor tags.

<asp:HyperLink runat="server" NavigateUrl="~/Contact" Text="Contact" />

Otherwise, when you try to navigate to Contact without making it application root relative, it assumes that Contact is one below the level of the last segment in the current URL (because URL's used to be tied to directories rather than semantic routes, ex: in www.website.com/Article/id/title it thinks title is the directory).

Note, you could also do some inline C# in a plain anchor tag similar to the way you did GetRouteUrl, but I can't remember off the top of my head the correct function call to use.ResolveUrl or ResolveClientUrl or something like that.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.