样式和脚本不加载URL重写后 [英] Styles and Scripts not Loading After URL-Rewriting
问题描述
我已经申请使用 UrlRewritingNet.UrlRewriter.dll
扩展一个URL重写规则到我的网站。在web.config文件中我写的规则如下所示:
I have applied a URL-rewrite rule to my web-site using UrlRewritingNet.UrlRewriter.dll
extension. On the web.config file I have written rules like the following:
<add name="Default"
virtualUrl="^~/(.*)/Default.zkn"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/Default.aspx?lang=$1"
ignoreCase="true"
/>
它很容易改变 http://sitename.com/en/Default.zkn
来的Default.aspx?LANG = EN
It easily changes http://sitename.com/en/Default.zkn
to Default.aspx?lang=en
我的头的一部分
部分是这样的:
<link href="Styles/Default.css" type="text/css" rel="Stylesheet" media="screen" />
但因为我已经申请对此,款式和附加JavaScript文件比较尖上的头不加载
部分。
然后我尝试添加〜
字符。
<link href="~/Styles/Default.css" type="text/css" rel="Stylesheet" media="screen" />
很多人说,这是可行的。但是,没有,它没有工作。
Many people said this would work. But no, it did not work.
页面加载后,我打开浏览器上的源和我看到〜
字符不是用我的站点文件夹代替。
After page loads I open the source on the browser and I see that ~
character was not replaced with my site folder.
所以对于CSS和JS文件时出现404错误。
So a 404 error occurs for the css and js files.
怎样才可以更正?
有没有办法来添加样式/ js文件也是一个新的URL重写规则?
Is there a way to add a new URL-rewriting rule for the style/js files also?
推荐答案
也许你可以试试:
<%
var basePath = String.Format("{0}{1}",Request.ApplicationPath, string.IsNullOrEmpty(Request.ApplicationPath) || !Request.ApplicationPath.EndsWith("/") ? "/" : "");
%>
<link href="<%=basePath%>Styles/Default.css" type="text/css" rel="Stylesheet" media="screen" />
这篇关于样式和脚本不加载URL重写后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!