I am going through a weird problem right now regarding routing in ASP.NET WebForms. The only reason I am trying to use routing is to achieve better looking URLs and nothing else. Also, this is the first time ever I am trying to implement routing.
My goal is simply:
http://www.domain.com/default.aspx –> http://www.mydomain.com/Home-Page
So, I have implemented the following in my global.asax
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
RegisterRoutes(RouteTable.Routes)
End Sub
and
Sub RegisterRoutes(ByVal routes As RouteCollection)
routes.MapPageRoute("homepage", "Home-Page", "~/Default.aspx")
End Sub
The goal is achieved however, all the images on my pages disappeared for logical reasons;
instead of locating img/someimage.png it was trying to get Home-Page/img/someimage.png
Now, I can of course correct the path for my images but that is going to take quite a long time. I would gladly get rid of routing instead.
My question:
Is there any way to prevent folders (images, css, js etc.) from getting affected by the routing mechanism and only achieve nice URLs?
You can tell routing to ignore specific file types. Make sure this entry comes before the specific routes.