正如标题,我已经实现了路由并且工作正常,但是 CSS js 和 jpg 文件的路径是错误的。
我包含了库 System.Web.Routing
并且它正确地出现在 web.config 中
<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>
从我写的标记中的 home.aspx 开始
<a href="search/shoes/" title="" > <img class="BorderHyperLinkImmagine" src="img/b5.jpg" alt="" /></a>
在以 CSS 开头的 global.asax 中,我在浏览器的开发工具中收到 404 错误到我所有本地链接(jpg、css、js)导致路由:
http://mysyte.com/search/shoese/style.css
代替:
http://mysyte.com/style.css
如您所见,有一些注释行,我已经尝试了所有这些行,但得到的结果相同,路径错误 (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
如浏览器中 home.aspx
和 lookupfortype.aspx
两处所示,该 URL 是正确的。我无法让它工作,我还能尝试什么,我该如何调试它,为什么忽略代码被路由忽略:-)
谢谢你的帮助
最佳答案
我是这样解决问题的:
<link rel="stylesheet" href="<%= Page.ResolveUrl("~/myStylysheet.css")%>" type="text/css" media="screen" />
我希望这对其他人有用。
关于asp.net - Aps.Net 4.0 网络表单路由有效但没有避免 css jpg js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21155126/