How to add mime type when using ASP.NET vNext?

There are LOADS of information on how to add MIME types to a regular project. These include configuring IIS or modifying web.config.

Both of these options are not available to me in vNext with IIS Express.

I looked at the diagram in the project.json file and could not find anything there that could help.

Can this be done yet? - I want to add a mime type for the extension .woff2.

+4
source share
2 answers

If you host it on IIS 7 or later, the next step will do what you need. This answer I used Visual Studio 2015 CTP5.

  • Publish your web application (ASP.net vnext)
  • You can publish it in a place like C: \ MyPublish
  • , C:\MyPublish\wwwroot. web.config.
  • IIS (, C:\MyPublish\wwwroot )
  • web.config , , mime. ( )
  <?xml version="1.0" encoding="utf-8"?>
   <configuration>
  <appSettings>
    <add key="kpm-package-path" value="..\approot\packages" />
    <add key="bootstrapper-version" value="1.0.0-beta2" />
    <add key="kre-package-path" value="..\approot\packages" />
    <add key="kre-version" value="1.0.0-beta2" />
    <add key="kre-clr" value="CLR" />
    <add key="kre-app-base" value="..\approot\src\WebApplication5" />
  </appSettings>
    <system.webServer>
        <staticContent>
            <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
        </staticContent>
    </system.webServer>
</configuration>

. . , Windows, web.config , , , linux env, .

: . Microsoft.AspNet.StaticFiles, .

public void Configure(IApplicationBuilder app)
        {
            app.UseStaticFiles();
        }

https://github.com/aspnet/StaticFiles/blob/dev/src/Microsoft.AspNet.StaticFiles/FileExtensionContentTypeProvider.cs. .

2: ( Mime)

 public void Configure(IApplicationBuilder app)
            {
                StaticFileOptions option = new StaticFileOptions();
                FileExtensionContentTypeProvider contentTypeProvider = (FileExtensionContentTypeProvider)option.ContentTypeProvider;
                contentTypeProvider.Mappings.Add("<<yourextention>>","<<mimetype>>");
                app.UseStaticFiles(option);
            }
+4

this, applicationhost.config, D:\Documents\IISExpress\config ( C [ ]).

:

<mimeMap fileExtension=".woff2" mimeType="font/x-woff2" />

<staticContent>.

+1

All Articles