asp.netwebformsseourl-routingwebforms-routing

Aps.Net 4.0 web forms routing works but is not avoiding css jpg js files


As title, I have implemented the routing and is working fine but the paths for CSS js and jpg files are wrong.

I included the library System.Web.Routing and it appears in the web.config correctly

<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </assemblies>
</compilation>

Start from home.aspx in the markup I wrote

 <a href="search/shoes/" title="" > <img  class="BorderHyperLinkImmagine"  src="img/b5.jpg" alt="" /></a>

than in the global.asax starting with CSS and I get 404 error in the dev tools of my browser to all my local link (jpg, css, js) cause the routing:

http://mysyte.com/search/shoese/style.css

istead of:

http://mysyte.com/style.css

As you can see there are some commented rows and I have tried all of them but I get the same result, wrong path(404).

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    'added for redirect and rewriting URL
    Me.RegisterRoutes(RouteTable.Routes)
End Sub

'added for redirect and rewriting URL
Sub RegisterRoutes(ByVal routeCollection As RouteCollection)
    'RouteTable.Routes.RouteExistingFiles = False
    routeCollection.Ignore("{resource}.css/{*pathInfo}")
    routeCollection.Ignore("{resource}.axd/{*pathInfo}")

    'routeCollection.Ignore("{*allcss}", New With {.allcss = ".*\.css(/.*)?"})
    'routeCollection.Ignore("{*alljpg}", New With {.alljpg = ".*\.jpg(/.*)?"})
    'routeCollection.Add(New Route("*\.css", New StopRoutingHandler()))
    'routeCollection.Ignore("{folder}/{*pathInfo}", New With {.folder = "css"})

     routeCollection.MapPageRoute("RouteForpage", "search/{type}/", "~/lookupfortype.aspx")
End Sub

The URL is correct as shown in the browser in both places home.aspx, and lookupfortype.aspx. I am not able to make it work, what can I try more and how can I debug this, why the ignore code is ignored by routing :-)

Thank you for your help


Solution

  • I solved the issue in this way:

    <link rel="stylesheet" href="<%= Page.ResolveUrl("~/myStylysheet.css")%>"  type="text/css" media="screen" />
    

    I hope this can be useful for someone else.