【发布时间】:2016-03-18 20:35:02
【问题描述】:
我正在开发托管在 Azure 云中的 MVC Web 应用程序。 一切正常,因为我制定了重写 URL 以强制 HTTPS 的规则:
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>
</rules>
</rewrite>
我的所有图像现在都不会在生产中显示。 这是我用来显示图像的剃须刀:
<img src="@Url.Content("~/Content/Images/Picture.png")" />
我试图推迟重写规则,但它似乎是“永久的”,即使相关代码在 web.config 中被注释。
我已经尝试将此添加到我的 web.config 中:
<configuration>
<location path="~/Content/Images">
<system.web>
<authorization>
<allow users="*"/> ---or even "?"
</authorization>
</system.web>
但没有任何改变。
有什么想法吗?
谢谢。
-- 编辑 为了最完整,这里是我的_layout页面的头节点:
@*@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")*@
@Styles.Render("~/Content/Site.css")
@Styles.Render("~/Content/Slick/slick.css")
@Styles.Render("~/Content/Slick/slick-theme.css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/Scripts/Slick/slick.min.js")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required:=False)
也许我把它们设置错了?这将是令人惊讶的,因为它以前有效。
顺便说一句,在调试模式下,我也没有更多的 CSS/JS 了!
【问题讨论】:
-
当您尝试直接从 yourwebsite/Content/Images/Picture.png 查看图片时会得到什么?
-
我在我的FF的F12菜单中看到了这个,它说找不到这个资源。事实上,它看起来像我在使用 HTTP 协议时找到的图片,但在使用 HTTPS 时就没有了。我的网站现在是https://myWebsite.com\Content\Images\Picures.png,我想这是从问题而来的。令人惊讶的是,当我在 web.config 中评论 url 重写并重新部署时,没有任何变化......
-
尝试使用 Fiddler 查看浏览器尝试下载图像时的 HTTP 响应是什么。这可能会为您提供有关问题所在的更多信息。
-
尝试将此添加到条件
-
@ChrisPietschmann 这是 Fiddler 所说的:“找不到资源”[...] 描述:HTTP 404。您正在寻找的资源(或其依赖项之一)可能已被删除,已更改名称,或暂时不可用。请查看以下 URL 并确保其拼写正确。请求的 URL:/Content/Site.css"。除了 /bundles/bootstrap 和 /bundle/jquery 之外的所有内容(css/JS/Images)都是一样的
标签: asp.net-mvc azure url-rewriting web-config