介绍
我通常会配置静态文件的 MIME,像这样(这很好用,继续阅读以获取实际问题):
var defaultStaticFileProvider = new PhysicalFileProvider(Path.Combine(webHostEnvironment.ContentRootPath, "content"));
var contentTypeProvider = new FileExtensionContentTypeProvider();
var defaultStaticFilesRequestPath = "/content";
// This serves static files from the 'content' directory.
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = defaultStaticFileProvider,
ServeUnknownFileTypes = false,
RequestPath = defaultStaticFilesRequestPath,
ContentTypeProvider = contentTypeProvider
});
之前的代码默认将.json扩展名映射为application/json,工作正常。
问题
我想要的是将该映射更改为application/manifest+json,但仅适用于一个文件:manifest.json
因此,我尝试添加另一个配置(不起作用):
// Add custom options for manifest.json only.
var manifestContentTypeProvider = new FileExtensionContentTypeProvider();
manifestContentTypeProvider.Mappings.Clear();
manifestContentTypeProvider.Mappings.Add(".json", "application/manifest+json");
var manifestStaticFileProvider = new PhysicalFileProvider(Path.Combine(webHostEnvironment.ContentRootPath, "content/en/app"));
var manifestStaticFileRequestPath = "/content/en/app/manifest.json";
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = manifestStaticFileProvider,
ServeUnknownFileTypes = false,
RequestPath = manifestStaticFileRequestPath,
ContentTypeProvider = manifestContentTypeProvider
});
为了澄清,我已经在之前的代码后面添加了上面的代码。
希望问题足够清楚,无论如何,我将检查评论以提出编辑建议,使其更好。