gpt4 book ai didi

c# - mimeMap 无法在 Azure 网站中工作

转载 作者:行者123 更新时间:2023-12-03 05:59:39 25 4
gpt4 key购买 nike

我有一个包含多个虚拟应用程序的 Azure 网站。根应用程序具有 SPA(角度)的 URL 重写规则:

<rule name="AngularJS" stopProcessing="true">
<match url=".*"/>
<conditions logicalGrouping="MatchAll">
<!--Is not file-->
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<!--Is not directory-->
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
<!--Is not /api-->
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
<!--Is not *.extension-->
<add input="{URL}" pattern="^.*\.(ashx|axd|css|gif|png|mov|MOV|avi|ttf|jpg|jpeg|js|flv|f4v|woff|woff2|json)$" negate="true"/>
</conditions>
<action type="Rewrite" url="/"/>
</rule>

根应用程序还有一个非常小的 OWIN/Katana 中间件应用程序,它运行静态文件中间件以根据条件返回单个页面。 RAMMFAR已关闭,静态文件中间件仅用于返回主页。

我的问题是,我的 .woff、.woff2 和 .json 文件拒绝在 Azure 中加载,但在本地 IIS 中加载正常。我有一个 web.config,其中包含以下内容:

<system.webServer>
<staticContent>
<remove fileExtension=".woff"/>
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff"/>

<remove fileExtension=".woff2"/>
<mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2"/>

<remove fileExtension=".json"/>
<mimeMap fileExtension=".json" mimeType="application/json"/>
</staticContent>
</system.webServer>

这在 Azure 中不起作用。它在本地运行良好,但在 Azure 中运行不佳。我什至将 web.configs 放在文件所在的每个文件夹中,以确保规则不会被覆盖。我认为这可能与在 Azure 网站中使用虚拟应用程序有关,但我无法更改我的网站结构。如何才能正确提供这些 .woff、.woff2 和静态 json 文件?编辑:刚刚检查了 IIS 日志,发现其中一个文件的请求跟踪失败。我收到“SECURITY_DENIED_BY_MIMEMAP”错误,这意味着这与 IIS 未获取 web.config 有关。

TLDR:即使我有适当的 web.config(据我所知),woff、json 和 woff2 文件也会返回 404,即使它们存在于服务器上的指定位置。

最佳答案

目前只有一种方法可以做到这一点,我已与 Azure 团队确认了这一点。

将 web.config 文件添加到应用程序的根目录 wwwroot\web.config ,其中包含以下内容

  <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="application/mp4" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
</system.webServer>
</configuration>

关于c# - mimeMap 无法在 Azure 网站中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34300258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com