asp.net - Aps.Net 4.0 网络表单路由有效但没有避免 css jpg js 文件

标签 asp.net webforms seo url-routing webforms-routing

正如标题,我已经实现了路由并且工作正常,但是 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.aspxlookupfortype.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/

相关文章:

javascript - 使用 ASP MVC 将跨度的数据绑定(bind)到数据库,使用 Model Binder

data-binding - 您如何在 Web 表单数据绑定(bind)表达式中使用扩展方法?

javascript - WebForm_DoPostBackWithOptions 未定义

seo - 在 Schema.org JSON-LD 中使用多个同类项目

php - Wordpress wp_head() 标题标签不工作

seo - 在我的网站上使用 rel nofollow 指向彼此是否安全?

asp.net - 将 &lt;script&gt; 标签注入(inject)到代码后面的 <head> 中

c# - ASP.NET 自动生成 aspx.designer.cs 关闭?

c# - 使用 ASP.NET C# 的 HTML5 视频控件

asp.net - 空 Page_Load() 方法的性能影响