Reputation: 17367
I'm using kpm pack to generate my deployment, which I deploy to Azure via ftp. I need to be able to serve static json files, so I need to add the following to my web.config:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="text/html" />
</staticContent>
</system.webServer>
The problem is that kpm pack generates the web.config, so the only way to accomplish this is to add the config section to the web.config after it's been generated. Since I'm doing automated deployments via ci, this would require a bit of effort. Is there a better way to accomplish this?
Upvotes: 4
Views: 1883
Reputation: 4194
In ASP.NET Core you may be able to avoid web.config
altogether by configuring the static file middleware options (StaticFileOptions
) in code, providing a custom FileExtensionContentTypeProvider
as its ContentTypeProvider
:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddInstance<IContentTypeProvider>(
new FileExtensionConentTypeProvider(
new Dictionary<string, string>(
// Start with the base mappings
new FileExtensionContentTypeProvider().Mappings,
// Extend the base dictionary with your custom mappings
StringComparer.OrdinalIgnoreCase) {
{ ".json", "text/html" }
}
)
);
...
}
public void Configure(
IApplicationBuilder app,
IContentTypeProvider contentTypeProvider)
{
...
app.UseStaticFiles(new StaticFileOptions() {
ContentTypeProvider = contentTypeProvider
...
});
...
}
Upvotes: 0
Reputation: 171
You should add your configurations to the source of web.config, instead of the target.
If you don't have a web.config in root of the project being packed, please create one. Then add your static content configurations to [project_root]/web.config.
"kpm pack" will preserve all configurations in [project_root]/web.config, add some information needed by IIS, and then write it to wwwroot/web.config.
Important Update:
A change was introduced in "kpm pack": https://github.com/aspnet/KRuntime/pull/972
Please move your web.config from project root to the source of wwwroot.
The source of wwwroot folder can be specified with 'webroot' in project.json (https://github.com/aspnet/Home/wiki/Project.json-file#webroot). You can also specify it with '--wwwroot' option of "kpm pack".
Upvotes: 2