繁体   English   中英

IIS URL重写模块:Url.Content()无法正确解析CSS / Image路径

[英]IIS URL Rewrite module: Url.Content() does not resolve CSS/Image path properly

我有一个标准的MVC3项目与布局页面等。现在我需要制作漂亮的URL。 我开始玩URL重写模块。 我正在尝试将http://localhost/Photographer/Pablohttp://localhost/category-about.aspx?displayName=Pablo ,这是我的重写规则(非常简单!):

  <system.webServer>
    <rewrite>
      <rules>
        <rule name="about" patternSyntax="Wildcard">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="\.png|\.js|\.css|\.jpg" negate="true" />
          </conditions>
          <match url="photographer/*" />
          <action type="Rewrite" url="category-about.aspx?displayName={R:1}" logRewrittenUrl="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

你看到我在google搜索试图解决问题后添加的所有条件 - 尽管他们没有帮助。

我找到了这个页面: http//www.iis.net/learn/extensions/url-rewrite-module/url-rewriting-for-aspnet-web-forms - 这表示在重写时服务器正确处理〜运算符规则适用。 但在我的情况下显然不会发生这种情况 - 请参阅附图:

图像附加

我的问题有什么解决方案? 我该如何引用CSS / JS文件? 我在IIS 7.5上使用MVC3。

更新:图像不是很清楚 - 但它显示我的MasterLayout页面有

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

但它已经解决了

http://localhost/Photographer/Content/Site.css - and it gives 404

代替

http://localhost/Content/Site.css - which gives 200

当我请求此URL时: http://localhost/Photographer/Pablo 逻辑工作正常 - 我的控制器获取请求并呈现页面 - 但它的CSS和图像丢失(因为它们有错误的根文件夹前置)。

尝试使用Request.ApplicationPath。 这样的事情应该有效:

<link href="@(Request.ApplicationPath + "Content/Site.css")" rel="stylesheet" type="text/css" />

你说线:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" />

被解决为

“http:// localhost / Photographer / Content / Site.css”

,这是绝对正确的,这是如何解决。 你的css在哪里,css中图像的路径是正确的吗?

而不是这个

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

试试这个没有波浪号(〜)

<link href="@Url.Content("/Content/Site.css")" rel="stylesheet" type="text/css" />

这应该解析为您想要的http://localhost/Content/Site.css

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM