I am trying to make use of URL routing in my web forms application to make urls more user friendly. I would like to use the following mapping for one of my pages:
/services --> common/services.aspx
/services/seo --> common/services.aspx#seo
/services/hosting --> common/services.aspx#web-hosting
Can anyone please help me write the correct routing for this scenario? I would basically want to redirect the user to the different sections on the same page with different URLs as listed above.
Some of the URLs which are already working are:
//About Us
routes.MapPageRoute("", "about", "~/common/about.aspx", false);
//Contact Us
routes.MapPageRoute("", "contact", "~/common/contact.aspx", false);
Only the first one of the following works-
//Services - works
routes.MapPageRoute("", "services/{service}", "~/common/services.aspx", false);
//does not work
routes.MapPageRoute("", "services/web-development", "~/common/services.aspx#web", false);
routes.MapPageRoute("", "services/seo", "~/common/services.aspx#seo", false);
routes.MapPageRoute("", "services/digital-marketing", "~/common/services.aspx#marketing", false);
3
Answers
For anyone facing similar problem, here's what i did finally. I set the routing of all Urls to the same page-
And moved the logic to jump to the section of the page to javascript (using jQuery):
This checks the url of the page and moves the window location to the appropriate section of the page.
Here’s an introduction to friendly urls: http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx
Web browsers will prevent the server-side (ASP.NET) from reading anything after the # fragment for security reason. so you will not be able to communicate between pages unless on the client-side (JavaScript)…