102

The Favicon Generator assembles a package for webmasters to use in order to have icons available for many different devices. The page comes with a file called site.manifest which is linked to via the following tag in the web page's document <head>:

<link rel="manifest" href="site.webmanifest">

According to Mozilla: "The web app manifest provides information about an application (such as name, author, icon, and description) in a JSON text file. The purpose of the manifest is to install web applications to the homescreen of a device, providing users with quicker access and a richer experience."

Unfortunately if you are using Microsoft's Internet Information Services (IIS), you'll get a 404.3 error if you try and access the site.webmanifest file.

The exact error message is as follows: "The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map."

How can I properly serve site.webmanifest files in IIS?

Dave L
  • 3,095
  • 3
  • 16
  • 25

6 Answers6

128

By default, IIS does not serve any files that does not have a MIME map associated with it in its (IIS) core settings.

To address this challenge, you will need to map the .webmanifest file extension to its appropriate MIME type.

To accomplish this, open IIS and follow the steps below;

  1. On the left hand side, select either your web site or the entire server in the "Connections" menu. If you select the server, your MIME mapping will apply to every web site on the server. If you select a web site, it will only apply to a single web site.

  2. Next, select "MIME Types" from the IIS menu:

MIME Types Menu Item

  1. Once there, click "add..." from the right hand menu.

  2. In the dialog box that opens specify .webmanifest in the file name extension box application/manifest+json in the MIME type box.

Add MIME Type dialog box

  1. Click "OK".

Congratulations; you've just defined the MIME type for .webmanifest on IIS.

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
Dave L
  • 3,095
  • 3
  • 16
  • 25
  • ... more details about the `.webmanifest` file extension [MIME type](https://www.w3.org/TR/appmanifest/#bib-mime-types) available [here](https://www.w3.org/TR/appmanifest/#dfn-media-type-for-a-manifest) – nyedidikeke Apr 19 '19 at 20:01
  • I did this and it broke all `.js` files on all sites on that server (for some reason, the server started serving them as `html` instead of `text/javascript`). Any reason why this would have happened? After removing the `.webmanifest` mime type in IIS, the sites went back to normal. – Paul Apr 29 '19 at 18:29
  • The funny thing is, I add it like explained, but it disappears a short while later and I get a 403 again, add it again, works a while then it disappears again etc. – Legends Dec 19 '19 at 00:22
  • apologies for the bump but I already have .manifest defined, by default I assume, as `application/x-ms/manifest`. Can I change this definition? Note that if I do change it, it still gives the error as posted by OP – nathanjw Jun 29 '20 at 19:39
  • 2
    @nathanjw, this topic was for `.webmanifest` files. `.manifest` and `.webmanifest` are not the same. Hope this helps. :) – Dave L Jun 30 '20 at 20:39
  • @DaveL darn it you're right! I was able to add .webmanifest as described above :) – nathanjw Jun 30 '20 at 21:50
  • For some reason even after doing this. IIS still doesn't want to serve it out. Anyone else have this issue? – Donny V. Aug 18 '20 at 21:30
  • 1
    @DonnyV. I have not experienced this problem on any of my Windows servers. Are you able to provide a screenshot of the MIME type you added? Also, what is the exact error you get back from IIS? Is it a 404.3? – Dave L Aug 19 '20 at 22:50
81

For Azure I added this as the web.config

<?xml version="1.0"?>

<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".json" mimeType="application/json" />
            <mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json" />
        </staticContent>
    </system.webServer>
</configuration> 
Richard Hubley
  • 2,180
  • 22
  • 29
  • 3
    Thank you! This is also fixes debugging using IIS Express. – Robert Smith Feb 25 '20 at 16:13
  • 1
    This is the better answer, because I don't have access on the server to set up mime types. – Peter Morris Jun 13 '20 at 12:03
  • 1
    Thanks ALOT, I was brooding over for this for more than 2 days. After this it really worked smoothly for both of my issues: Offline Caching and installing the web app feature. – ASR Jul 31 '20 at 18:46
  • 3
    If `json` is already a valid mime type, remove the json mapping to prevent an error on IIS. In other words, remove this line: `` – Metro Smurf Feb 24 '21 at 21:51
66

For those using ASP.NET Core (I am using 2.1) you can configure the MIME types that can be served in the application Startup.cs file as per the static files docs:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    FileExtensionContentTypeProvider provider = new FileExtensionContentTypeProvider();
    provider.Mappings[".webmanifest"] = "application/manifest+json";

    app.UseStaticFiles(new StaticFileOptions()
    {
        ContentTypeProvider = provider
    });

    app.UseMvc();
}
Ben
  • 5,525
  • 8
  • 42
  • 66
  • +1 this worked for Kestrel too, i.e. when not running project on IIS, but using a local profile in `launchSetting.json` – J86 May 10 '20 at 09:58
  • 1
    if you're already using static files via app.UseStaticFiles(), make sure to call *both* UseStaticFiles() and UseStaticFiles(new StaticFileOptions()...) else all your other files will stop getting served. – Mike Sep 09 '20 at 18:48
  • Note that it needs to be added manually up to .NET core 3.1. In .NET Core 5.0 it has been included in the default provider mappings, and trying to add it manually will cause exceptions since it's already there. – Henric Rosvall May 12 '21 at 09:14
16

Easier solution is to rename your manifest file to site.webmanifest.json and link as

 <link rel="manifest" href="site.webmanifest.json">

IIS should already have a MIME Type for .json files This is also helpful if deploying to Azure where its not so easy to change the IIS settings.

Peter Kerr
  • 1,649
  • 22
  • 33
  • 4
    I agree that renaming the file to *.json made the most sense to me originally. Especially since the file is indeed JSON data. However, there were some strong opinions against doing so in the following thread where my problem originated: https://github.com/RealFaviconGenerator/realfavicongenerator/issues/372 – Dave L Nov 08 '18 at 19:31
  • 1
    Per the current W3C working draft these files must be named .webmanifest. Yes, currently browsers are using .json but they can according to spec change that on a whim and then it would break your PWA. – aallord Apr 10 '19 at 20:31
9

Adding to @Ben's answer: if you have a SPA you should put StaticFileOptions code into the UseSpaStaticFiles() call:

FileExtensionContentTypeProvider provider = new FileExtensionContentTypeProvider();
provider.Mappings[".webmanifest"] = "application/manifest+json";

app.UseSpaStaticFiles(new StaticFileOptions()
{
    ContentTypeProvider = provider
});
Cezar Crintea
  • 301
  • 4
  • 7
0

I found that the IIS server had ".json" listed in the Request Filtering feature saying it was not allowed.

enter image description here

Removing that allowed the file to be served.

Glen Little
  • 6,951
  • 4
  • 46
  • 68