Try using tilde slash like so "~/MyProject/Page1" in your controls when writing out URLs.
Use Request.ApplicationPath + "/MyProject/Page1" when making URLs in code such as C#.
And use <%= Page.ResolveUrl("~/") %>MyProject/Page1 in .aspx files when creating URLs.
Doing any of the above will insure URLs will start from the root of the application and not relative to the current URL in the address bar which appears to be whats happening in your case.
There must be some programming conflict with {Name} . Try to user {Name} in first route and something else like {NewsName} in other route for news. This must help you to debug and resolve the issue quickly.
When linking files such as css and javascript in your .aspx files do the following:
<script src="<%= Page.ResolveUrl("~/") %>Path/To/jquery.js" type="text/javascript" />
This will have the same result as Request.ApplicationPath which was used in the code behind.
anuj_koundal
Contributor
2253 Points
538 Posts
Asp .Net 4.0 URL Routing Issue.
Aug 31, 2012 05:52 AM|LINK
Hi
I am using Url Routing for first time (4.0) I have following issue.
I have two route urls
System.Web.Routing.RouteTable.Routes.MapPageRoute( "RoutePages", "{Name}", "~/Content.aspx" ); System.Web.Routing.RouteTable.Routes.MapPageRoute( "RouteNews", "News/{Name}", "~/news.aspx" );And my Menu structure is like this.
http://localhost:61049/MyProject/Page1
http://localhost:61049/MyProject/Page2
http://localhost:61049/MyProject/Page3
http://localhost:61049/MyProject/News/NewsType1
http://localhost:61049/MyProject/News/NewsType1
Both type of above links works perfectly. But once I go to news links and then tries to go to page links the url becomes like
http://localhost:61049/MyProject/News/Page1 But Url has to be http://localhost:61049/MyProject/Page1
So the page not working. Also when I goes to News pages My Jquery also stops working.Any Solution.
Thanks
Anuj Koundal
My Blog
Mark as Answer on the post that helps you.
jprochazka
Contributor
4992 Points
748 Posts
Re: Asp .Net 4.0 URL Routing Issue.
Aug 31, 2012 05:58 AM|LINK
Try using tilde slash like so "~/MyProject/Page1" in your controls when writing out URLs.
Use Request.ApplicationPath + "/MyProject/Page1" when making URLs in code such as C#.
And use <%= Page.ResolveUrl("~/") %>MyProject/Page1 in .aspx files when creating URLs.
Doing any of the above will insure URLs will start from the root of the application and not relative to the current URL in the address bar which appears to be whats happening in your case.
foreversky
Member
84 Points
12 Posts
Re: Asp .Net 4.0 URL Routing Issue.
Aug 31, 2012 06:12 AM|LINK
Hi Anuj
There must be some programming conflict with {Name} . Try to user {Name} in first route and something else like {NewsName} in other route for news. This must help you to debug and resolve the issue quickly.
Hope that will sort out the issue.
anuj_koundal
Contributor
2253 Points
538 Posts
Re: Asp .Net 4.0 URL Routing Issue.
Aug 31, 2012 06:19 AM|LINK
Thanks for quick reply I have understand your answer but not able to implement
I am creating my menu dynamically in .cs file like
menu.Append("<li><a href=\"" + drChild["page_url"].ToString() + "\">" + drChild["page_menuLinkTitle"].ToString() + "</a></li>");and once the menu is created I bind it to .aspx page.
Anuj Koundal
My Blog
Mark as Answer on the post that helps you.
anuj_koundal
Contributor
2253 Points
538 Posts
Re: Asp .Net 4.0 URL Routing Issue.
Aug 31, 2012 06:21 AM|LINK
@foreversky
Thnks but not worked.
Anuj Koundal
My Blog
Mark as Answer on the post that helps you.
jprochazka
Contributor
4992 Points
748 Posts
Re: Asp .Net 4.0 URL Routing Issue.
Aug 31, 2012 07:28 AM|LINK
Try this:
menu.Append("<li><a href=\"" + Request.ApplicationPath + "/" + drChild["page_url"].ToString() + "\">" + drChild["page_menuLinkTitle"].ToString() + "</a></li>");More information on Request.ApplicationPath:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx
anuj_koundal
Contributor
2253 Points
538 Posts
Re: Asp .Net 4.0 URL Routing Issue.
Aug 31, 2012 09:31 AM|LINK
Thanks jprochazka It works. Only one issue is left jQuery stops working on
http://localhost:61049/MyProject/News/NewsType1
pages
Anuj Koundal
My Blog
Mark as Answer on the post that helps you.
jprochazka
Contributor
4992 Points
748 Posts
Re: Asp .Net 4.0 URL Routing Issue.
Aug 31, 2012 03:00 PM|LINK
When linking files such as css and javascript in your .aspx files do the following:
<script src="<%= Page.ResolveUrl("~/") %>Path/To/jquery.js" type="text/javascript" />
This will have the same result as Request.ApplicationPath which was used in the code behind.