无法从 Azure Web App 提供没有扩展名的文本文件

问题描述 投票:0回答:1

我正在尝试在 Web 应用程序中提供一个没有扩展名的文本文件。

该文件位于 .well-known 文件夹中。 .wellknown 文件夹中的其他文件(带有 json 扩展名)是可以访问的,但是当我尝试访问没有扩展名的文件时,应用程序会重定向到主页。

我修改了 web.config 并添加了对 2 个 mime 类型的支持(如下所示),但没有得到积极的结果。

现在 web.config 的内容如下所示:

?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Slp.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<staticContent> 
          <mimeMap fileExtension=".json" mimeType="application/json" />
          <mimeMap fileExtension="." mimeType="application/json" />
</staticContent>
    </system.webServer>
  </location>
</configuration>

任何建议将不胜感激。

azure azure-web-app-service text-files mime-types
1个回答
0
投票

这篇文章中解决方案的第 4 步apple-app-site-association to return as application/JSON from a azure request解决了这个问题。我添加了一个重写规则,以便在请求没有扩展名的文件时提供 json 文件。

web.config 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Slp.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
      <rewrite>
        <rules>
          <rule name="apple_json_file" stopProcessing="true">
             <match url="^.well-known/apple-app-site-association" />
             <action type="Rewrite" url=".well-known/apple-app-site-association.json" />
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
  </location>
</configuration>

我使用 apple-app-site-association.json 而不是 apple-app-site-association 作为文件名,并将其放在 .wellknown 文件夹中。

© www.soinside.com 2019 - 2024. All rights reserved.