Click here to Skip to main content
15,886,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have website developed in vb.net. I have many pages which is template based means structure is same just according to parameters it's page name & content gets changed. So I have define routing in my global.asax file. Problem is it is working only for one page which is on top. in following code..

Here I have two pages now with different links but if page link consist of second page then too it gets redirected to first page only. Means If I routed a page to DynamicPage then to it gets routed to shop2 page. How to solve this problem to support routing as defined.

What I have tried:

VB
Private Sub Application_Start(sender As Object, e As EventArgs)
    RegisterRoutes(RouteTable.Routes)
End Sub

Private Shared Sub RegisterRoutes(routes As RouteCollection)
    routes.MapPageRoute("shop2", "{name}.aspx", "~/shop2.aspx")
    routes.MapPageRoute("DynamicPage", "{product_name}.aspx", "~/DynamicPage.aspx")
End Sub
Posted
Updated 17-Jul-16 3:25am
v4

1 solution

From the point of view of the mapper, these two mappings are the same, so everything that fits the second also fits the first and therefore you never will be redirected to the second...
Try something like this:
VB
Private Shared Sub RegisterRoutes(routes As RouteCollection)
    routes.MapPageRoute("shop2", "{name}.aspx", "~/shop2.aspx")
    routes.MapPageRoute("DynamicPage", "product/{name}.aspx", "~/DynamicPage.aspx")
End Sub

Read more here: RouteCollection.MapPageRoute Method (System.Web.Routing)[^]
 
Share this answer
 
v2
Comments
SuRaj Dedhia 17-Jul-16 10:29am    
Thanks.. I can't believe I have made such a silly mistake.. This solved problem but is there any other way as this result lot of broken links and images on page. Just asking for knowledge?
Kornfeld Eliyahu Peter 17-Jul-16 10:30am    
Welcome!
We all made it - especially after steering too long at the code :-)...
SuRaj Dedhia 17-Jul-16 10:37am    
But on page lot of images & links broken due to path changed. How can we fix that?

Kornfeld Eliyahu Peter 17-Jul-16 10:40am    
Make them right - relative to the page and not absolute... (but truly I can't say without seeing it at all)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900