【问题标题】:IIS 7 no images when friendly url is on打开友好网址时,IIS 7没有图像
【发布时间】:2015-08-27 05:39:14
【问题描述】:

我正在使用两个简单的规则来实现友好的url。

他们正在寻找,但我看不到图像并且有一个错误

ASP.NET 3.5 网站的友好网址

http://localhost/Test/Products/888/9999

错误

http://localhost/Test/Products/888/Images/Jellyfish.jpg加载失败 资源:服务器响应状态为 404(未找到)

规则

  <rule name="t2" enabled="true">
                    <match url="^products/([0-9]+)/([0-9]+)" negate="false" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="products.aspx?p={R:1}&amp;pc={R:2}" />
                </rule>
                <rule name="t1" enabled="true">
                    <match url="^product/([0-9]+)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="product.aspx?p={R:1}" />
                </rule>

我看到 IIS 正在构建错误的图像路径,就像它说的那样

http://localhost/Test/Products/888/Images/Jellyfish.jpg

有什么线索吗?

【问题讨论】:

  • 我不太明白。除了 url http://localhost/Test/Products/888/9999 之外,您是返回位置 http://localhost/Test/Products/888/Images/Jellyfish.jpg 的图像,还是您的 product.aspx 返回图像。你想获取的图片的真实网址是什么?
  • @PeterHahndorf 网址http://localhost/Test/Products/888/9999 用于打开 Products.aspx。但不知何故,IIS 正在重写此页面内图像的路径。此页面有一个简单的``,无需重写规则即可正常工作。
  • 因此图像的 src 是相对于页面的,浏览器将请求类似 `localhost/Test/Products/888/9999/images/jellyfish.jpg' 的内容,这将由您的重写规则获取。在 F12 浏览器工具中,检查图像的实际请求 url。您必须从规则中排除图像或使用非相对路径。
  • @PeterHahndorf 我该怎么做?
  • 您可以在规则中添加&lt;conditions&gt;&lt;add input="{REQUEST_URI}" pattern="\.jpg" negate="true" /&gt;&lt;/conditions&gt; 之类的条件,或者&lt;conditions&gt;&lt;add input="{REQUEST_URI}" matchType="IsFile" negate="true" /&gt;&lt;/conditions&gt; 您必须确保您的图像不符合规则。

标签: asp.net iis-7 friendly-url url-rewrite-module


【解决方案1】:

我终于在这里找到了答案Missing CSS file and images after URL rewrite

我们必须在 MasterPage 的标题中使用这一行

<base href="//your.domain.here" />

你可以在这里阅读http://www.w3schools.com/tags/tag_base.asp

【讨论】:

    猜你喜欢
    • 2013-10-09
    • 1970-01-01
    • 2012-04-27
    • 2013-08-10
    • 2012-10-15
    • 2016-03-11
    • 2011-02-15
    • 1970-01-01
    • 2013-08-31
    相关资源
    最近更新 更多