开放全部静态资源的配置
This commit is contained in:
parent
90fc6d10ed
commit
4b80b16ca6
@ -23,6 +23,7 @@
|
|||||||
"LogError": false // 是否输出异常日志
|
"LogError": false // 是否输出异常日志
|
||||||
},
|
},
|
||||||
// 静态资源处理方式(允许这些文件被访问)
|
// 静态资源处理方式(允许这些文件被访问)
|
||||||
|
// 包含".*": "application/octet-stream"允许访问所有静态资源
|
||||||
"StaticContentTypeMappings": {
|
"StaticContentTypeMappings": {
|
||||||
".dll": "application/octet-stream",
|
".dll": "application/octet-stream",
|
||||||
".exe": "application/octet-stream",
|
".exe": "application/octet-stream",
|
||||||
|
|||||||
@ -20,12 +20,14 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.AspNetCore.ResponseCompression;
|
using Microsoft.AspNetCore.ResponseCompression;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using OnceMi.AspNetCore.OSS;
|
using OnceMi.AspNetCore.OSS;
|
||||||
using SixLabors.ImageSharp.Web.DependencyInjection;
|
using SixLabors.ImageSharp.Web.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Unicode;
|
using System.Text.Unicode;
|
||||||
@ -278,15 +280,37 @@ public class Startup : AppStartup
|
|||||||
var cpMappings = App.GetConfig<Dictionary<string, string>>("StaticContentTypeMappings");
|
var cpMappings = App.GetConfig<Dictionary<string, string>>("StaticContentTypeMappings");
|
||||||
if (cpMappings != null)
|
if (cpMappings != null)
|
||||||
{
|
{
|
||||||
foreach (var key in cpMappings.Keys)
|
if (cpMappings.Keys.Contains(".*"))
|
||||||
{
|
{
|
||||||
contentTypeProvider.Mappings[key] = cpMappings[key];
|
app.UseStaticFiles(new StaticFileOptions
|
||||||
|
{
|
||||||
|
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "wwwroot")),
|
||||||
|
//RequestPath = "/static",
|
||||||
|
ServeUnknownFileTypes = true, // 允许服务未知文件类型,以便能处理.dll这种非默认的静态文件类型
|
||||||
|
//DefaultContentType = "application/octet-stream" // 为未知文件类型设置一个通用的内容类型
|
||||||
|
DefaultContentType = cpMappings[".*"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var key in cpMappings.Keys)
|
||||||
|
{
|
||||||
|
contentTypeProvider.Mappings[key] = cpMappings[key];
|
||||||
|
}
|
||||||
|
app.UseStaticFiles(new StaticFileOptions
|
||||||
|
{
|
||||||
|
ContentTypeProvider = contentTypeProvider
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.UseStaticFiles(new StaticFileOptions
|
else
|
||||||
{
|
{
|
||||||
ContentTypeProvider = contentTypeProvider
|
app.UseStaticFiles(new StaticFileOptions
|
||||||
});
|
{
|
||||||
|
ContentTypeProvider = contentTypeProvider
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//// 启用HTTPS
|
//// 启用HTTPS
|
||||||
//app.UseHttpsRedirection();
|
//app.UseHttpsRedirection();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user