asp.net-core - .Net核心请求过滤和文件下载
问题描述
我们有一个 .net 核心 Web 应用程序,它只是为我们的一些客户端应用程序更新托管文件。
我们决定在其中一个客户端应用程序中添加应用程序洞察,文件 ApplicationInsights.config 是更新的一部分。
对https://server/path/to/update/ApplicationInsights.config的请求会引发 404 错误。
到目前为止,我已经尝试过:
- 在启动时在静态文件定义中添加“.config”扩展名:无效(这适用于 .exe 和 .dll)
- 启用此文件夹的文件夹浏览,仍然没有效果
它似乎与一些开箱即用的请求过滤有关。
问题是 :
如何禁用特定文件夹的所有下载限制(最佳)
或者
如何禁用 *.config 文件的所有过滤
先感谢您
解决方案
这是因为默认FileExtensionContentTypeProvider
不提供*.config
文件映射。
要使其服务*.config
文件,只需创建您自己的ContentTypeProvider
,或添加映射*.config
:
var myContentTypeProvider= new FileExtensionContentTypeProvider();
myContentTypeProvider.Mappings.Add(".config","text/plain");
app.UseStaticFiles(new StaticFileOptions{
RequestPath = "/path/to/update",
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(),"path/to/update"),
ExclusionFilters.None
),
ContentTypeProvider = myContentTypeProvider,
});
[更新]
经过讨论,以下Web.Config
(由OP)有效:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions>
<remove fileExtension=".config" />
<add fileExtension=".config" allowed="true" />
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
</configuration>
推荐阅读
- java - 如何将二进制字符串转换为十六进制并在java中通过Uart端口发送
- angular - 在ionic4中自动读取短信不起作用
- python - 如何使用networkx nx.draw()使x和y轴出现?
- entity - 两个聚合根之间的 DDD 共享实体
- jquery - 检查两个字段以输入字符
- python - 如何在python中将日期时间列重置为一分钟的增量
- java - Java https 请求获取 curseforge 站点的 403 响应代码
- python - Python,如何通过查找或 .map 交互两个不同的数据帧
- java - 从 ViewModel MutableLiveData 获取值并将它们显示在文本字段上
- arrays - 如何用 Excel 行(字符串)填充组合框?