4

There's LOADS of information on how to add MIME types into a normal project. These include configuring IIS, or modifying the web.config.

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

I had a look at the schema to the project.json file and couldn't find anything in there that would help either.

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

2 Answers 2

4

If you hosting it on IIS 7 or later then following step will do what you need. This answer I have used Visual Studio 2015 CTP5.

  1. Publish your web application ( ASP.net vnext)
  2. You can publish it to location like C:\MyPublish
  3. Once it get successfully published you will find following location C:\MyPublish\wwwroot. Here You will find web.config.
  4. Now host your site to in IIS ( Make sure that you have used C:\MyPublish\wwwroot as your path)
  5. Now edit web.config over here just like you did for old version to add mime type. ( Following is my edit)
  <?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>

Note: As per my thinking In old version it is fix that it is always windows environment so we have direct web.config file in project and we edit that but now we have to follow different process to register as in future we can host completly on linux env as well.

Update : There is another way to do that as well. If you are using Microsoft.AspNet.StaticFiles package then you will have extension.

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

This will indirectly use https://github.com/aspnet/StaticFiles/blob/dev/src/Microsoft.AspNet.StaticFiles/FileExtensionContentTypeProvider.cs. Here you can see all mapping.

Update 2: (Add New Mime Type)

 public void Configure(IApplicationBuilder app)
            {
                StaticFileOptions option = new StaticFileOptions();
                FileExtensionContentTypeProvider contentTypeProvider = (FileExtensionContentTypeProvider)option.ContentTypeProvider;
                contentTypeProvider.Mappings.Add("<<yourextention>>","<<mimetype>>");
                app.UseStaticFiles(option);
            }
Sign up to request clarification or add additional context in comments.

1 Comment

How can you add more mapping ? .json for example ?
1

Until this is released, you can also edit applicationhost.config which I found in D:\Documents\IISExpress\config (yours might be on your C drive [Documents]).

I added:

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

Inside <staticContent>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.