问题描述
我正在尝试在IIS上部署我的mvc angular应用程序,到目前为止一切工作都很好。但是,现在我需要提供一些带有自定义扩展名的静态文件(例如 .dma )。为此,我为我的站点添加了适当的MIME类型配置,但是它似乎不起作用。
二进制文件的一般结构如下:
.
+-- Angularapp
| +-- dist
| +-- assets
| +-- specialfile.dma
| +-- ...
+-- index.html
+-- wwwroot
| +-- icon.svg
+-- appsettings.json
+-- web.config
+-- *.dll
我的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=".\mywebapp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".dma" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</configuration>
当我尝试从资产文件夹中获取扩展名为 .dma 的文件时,找不到该文件。 我已经检查过是否可以从同一文件夹中检索任何其他文件(例如png图像),因此路由很好。
我还独立于MVC应用程序部署了我的angular应用程序,事实证明我可以获取文件。
我在这里想念什么?
我还需要添加其他配置吗?
解决方法
我认为,一旦部署站点,“ system.webServer”元素中的任何内容都需要在IIS中进行配置。除非您修改IIS应用程序配置,否则IIS应用程序配置将覆盖web.config。
,您可以尝试以下方法进行故障排除:
1。能否直接从浏览器中请求.dma文件,看看您得到的共振标头是什么?
2。启用Failed Request Tracing并在“完成请求跟踪”标签中查找GENERAL_RESPONSE_HEADERS部分。
,经过一段时间的故障排除后,我终于弄明白了发生了什么。
事实证明,代码中有一个配置更改了角度文件的根路径。
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "AngularApp/dist";
});
看来IIS只是忽略了此文件夹的任何常规配置。
我必须为assets文件夹创建一个虚拟目录,并将MIME类型配置添加到新的位置标记中。
所以,我的web.config现在看起来像这样。
<configuration>
...
<location path="assets">
<system.webServer>
<staticContent>
<mimeMap fileExtension=".dma" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
</location>
</configuration>