我创建了一个包含一些 View 和 Controller 的 MVC 5 网页,添加了一些图像(gif 和 svg),并验证它主要在本地工作。图像显示出来,一切都按预期运行。
当我部署到 Azure 时,gif 图像加载正常,但 svg 图像给我错误您正在查找的资源已被删除、名称已更改或暂时不可用。
当我使用 Azure 凭据登录网站的 FTP 时,gif 和 svg 文件都在那里。我可以从网络访问我的 /img/loading.gif
文件;但是,/img/logo.svg
- 虽然它确实存在于目录中并且确实在我本地运行时显示 - 在我的 Azure 网站提供服务时找不到。
我认为这不相关,但我告诉我的网站路由现有文件:
routes.RouteExistingFiles = true;
我的所有图像(gif 和 svg)均位于 Solution 'mySolutionName' -> myMvcProjectName -> img
中。因此,我看不到任何内容指示我的网站以不同方式处理这些文件。
最佳答案
事实证明这是 staticContent
的问题MIME 类型,如 this answered question .
为了解决这个问题,我找到了我的 <system.webServer>
我的部分Web.config
:
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
并添加了<staticContent>
使用适当的 MIME 类型映射 SVG:
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
<staticContent>
<mimeMap fileExtension="svg" mimeType="image/svg+xml" />
</staticContent>
</system.webServer>
关于asp.net-mvc - Azure 上的 ASP.NET MVC 5 : "The resource you are looking for has been removed..." for SVG files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26516356/