I have the following line in Global.asax.cs
:
routes.MapPageRoute( "Resorts", "{resortname}", "~/Pages/ViewResort.aspx" );
The intention is to allow a request like:
www.mysite.com/some-resort-name
to load this resource (more or less)
www.mysite.com/Pages/ViewResort.aspx?resortname=some-resort-name
This behavior works fine. However, I'm noticing that ViewResort.aspx
is being loaded every time any resource is requested, presumably because my route doesn't contain a literal path segment, like this alternative would:
routes.MapPageRoute( "Resorts", "Resort/{resortname}", "~/Pages/ViewResort.aspx" );
My client is insistent that the only thing after the hostname in the URL be the resort name, so going with the alternate route is not a possibility.
So my question is: is there something special one needs to do to the RouteUrl
when it refers to the site's root directory? Failing that, is there a particular pattern that can be implemented on the target page (ViewResort.aspx
in this case) to prevent it from being loaded and discarded with each page request?
Your route is acting as a catch-all. In situations like this, you'll need to provide specific routes before the catch-all route in order to give the proper responses for those specific routes. In other words, the only routes that should get through to your catch-all are routes that must redirect to Pages/ViewResort.aspx.