Configuring web.config for ASP.NET 5 (vNext) deployments

I am using the kpm package to create my deployment, which I am deploying 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 a web.config file, so the only way to do this is to add a configuration section to the web.config file after it is created. Since I am performing automatic deployment through ci, this will take a little effort. Is there a better way to do this?

+4
source share
2 answers

You should add your configurations to the web.config source, not the target.

web.config , , . [project_root]/web.config.

"kpm pack" [project_root]/web.config, , IIS, wwwroot/web.config.

:

"kpm pack" : https://github.com/aspnet/KRuntime/pull/972

, web.config wwwroot.

wwwroot 'webroot' project.json(https://github.com/aspnet/Home/wiki/Project.json-file#webroot). '--wwwroot' "kpm pack" .

+2

ASP.NET Core web.config (StaticFileOptions) , FileExtensionContentTypeProvider 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
        ...
    });
    ...
}
0

All Articles