But i have route my url successfully but the issue i am facing is both pages shows me same page about-us !! How can i route more than one page on above code ?? Am i making any mistake in code ?? Please help asap.
If you notice they are structured exactly the same {<something>}/{<something>} so the first one will be triggered no mater what. What you will want to do is define them better an example would be:
Now each route is defined by either /about/... in the first and /contact/... in the later. Of course you can define your route anyway you like just make sure they are not structured
exactly the same and with no way for the system to define it specifically for a page.
But i want to show just
about in url not about/about-us .. where above code shows in url about/about-us and contact/contacu-us.. I jst want to show
about-us and contact-us in url.
Hello again and thnx 4 rpl.. You are correct. I tried above one got success. I will mark it as an answer but one more question before. If i want to convert
contact-us.aspx?Id=2 into contact-us/id=2 what should i try ?? Xtrmly sorry i am not familier with url routing that's why asking too many questions.
Nirav Golani
Member
745 Points
257 Posts
Url routing issue
Dec 26, 2012 01:04 PM|LINK
Hello all,
In my global.ascx i wrote code below to route my url:
static void RegisterRoutes(RouteCollection routes) { routes.Ignore("{resource}.axd/{*pathInfo}"); routes.MapPageRoute("Pages", "{Name}/{*queryvalues}", "~/about-us.aspx"); routes.MapPageRoute("MapPages", "{Contact}/{*queryvalues}", "~/contact-us.aspx"); }But i have route my url successfully but the issue i am facing is both pages shows me same page about-us !! How can i route more than one page on above code ?? Am i making any mistake in code ?? Please help asap.
Nirav Golani.
Nirav Golani
Member
745 Points
257 Posts
Re: Url routing issue
Dec 26, 2012 01:28 PM|LINK
Isn' there any one to help ?? Want to route more than one pages by above code in global.ascx
Nirav Golani.
jprochazka
Contributor
4886 Points
740 Posts
Re: Url routing issue
Dec 26, 2012 01:35 PM|LINK
Problem is your routes are too generic with no defining "feature".
Your routes look like so:
routes.MapPageRoute("Pages", "{Name}/{*queryvalues}", "~/about-us.aspx");
routes.MapPageRoute("MapPages", "{Contact}/{*queryvalues}", "~/contact-us.aspx");
If you notice they are structured exactly the same {<something>}/{<something>} so the first one will be triggered no mater what. What you will want to do is define them better an example would be:
routes.MapPageRoute("Pages", "about/{Name}/{*queryvalues}", "~/about-us.aspx");
routes.MapPageRoute("MapPages", "contact/{Contact}/{*queryvalues}", "~/contact-us.aspx");
Now each route is defined by either /about/... in the first and /contact/... in the later. Of course you can define your route anyway you like just make sure they are not structured exactly the same and with no way for the system to define it specifically for a page.
Nirav Golani
Member
745 Points
257 Posts
Re: Url routing issue
Dec 26, 2012 01:40 PM|LINK
Hi jprochazka,
First of all thnx for the rpl.. I am trying to solve just a minute
Nirav Golani.
Nirav Golani
Member
745 Points
257 Posts
Re: Url routing issue
Dec 26, 2012 01:54 PM|LINK
Hello again jprochazka,
What you were telling was right and tried below code earlier.
routes.MapPageRoute("Pages", "about/{Name}/{*queryvalues}", "~/about-us.aspx");
routes.MapPageRoute("MapPages", "contact/{Contact}/{*queryvalues}", "~/contact-us.aspx");
But i want to show just about in url not about/about-us .. where above code shows in url about/about-us and contact/contacu-us.. I jst want to show about-us and contact-us in url.
Nirav Golani.
jprochazka
Contributor
4886 Points
740 Posts
Re: Url routing issue
Dec 26, 2012 02:12 PM|LINK
Try the following maybe:
routes.MapPageRoute("AboutRoute", "about-us/{*queryvalues}", "~/about-us.aspx");
routes.MapPageRoute("ContactRoute", "contact-us/{*queryvalues}", "~/contact-us.aspx");
Unless your using {Name} and/or {Contact} to get data you need to use in code.
Nirav Golani
Member
745 Points
257 Posts
Re: Url routing issue
Dec 27, 2012 10:28 AM|LINK
Hello again and thnx 4 rpl.. You are correct. I tried above one got success. I will mark it as an answer but one more question before. If i want to convert contact-us.aspx?Id=2 into contact-us/id=2 what should i try ?? Xtrmly sorry i am not familier with url routing that's why asking too many questions.
Nirav Golani.
anurag003iit...
Member
176 Points
111 Posts
Re: Url routing issue
Dec 27, 2012 10:33 AM|LINK
HI,
try this
http://stackoverflow.com/questions/3732310/managing-routes-global-asax-maintainability
Nirav Golani
Member
745 Points
257 Posts
Re: Url routing issue
Dec 27, 2012 10:38 AM|LINK
Anurag,
Its not working for me.
Nirav Golani.