问题
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"
/>
It easily changes http://sitename.com/en/Default.zkn
to Default.aspx?lang=en
A part of my head
section is like the following:
<link href="Styles/Default.css" type="text/css" rel="Stylesheet" media="screen" />
But since I have applied this, The styles and the additional javascript files pointed relatively on the head
section are not loaded.
Then I have tried to add ~
character.
<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.
So a 404 error occurs for the css and js files.
How can it be corrected?
Is there a way to add a new URL-rewriting rule for the style/js files also?
回答1:
Maybe you can try :
<%
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" />
来源:https://stackoverflow.com/questions/16208473/styles-and-scripts-not-loading-after-url-rewriting