How Can I have IIS properly serve .webmanifest files on my web site?
Asked Answered
M

6

106

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?

Mellott answered 29/3, 2018 at 23:26 Comment(0)
M
137

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.

Mellott answered 29/3, 2018 at 23:26 Comment(9)
... more details about the .webmanifest file extension MIME type available hereMendelsohn
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.Connatural
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.Dikdik
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 OPManciple
@nathanjw, this topic was for .webmanifest files. .manifest and .webmanifest are not the same. Hope this helps. :)Mellott
@DaveL darn it you're right! I was able to add .webmanifest as described above :)Manciple
For some reason even after doing this. IIS still doesn't want to serve it out. Anyone else have this issue?Trencherman
@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?Mellott
It worked well when I follow this guide.Hushhush
O
84

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> 
Osteomalacia answered 8/11, 2018 at 14:3 Comment(4)
Thank you! This is also fixes debugging using IIS Express.Blaspheme
This is the better answer, because I don't have access on the server to set up mime types.Schouten
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.Montane
If json is already a valid mime type, remove the json mapping to prevent an error on IIS. In other words, remove this line: <mimeMap fileExtension=".json" mimeType="application/json" />Harmon
G
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();
}
Gazetteer answered 12/11, 2018 at 16:18 Comment(3)
+1 this worked for Kestrel too, i.e. when not running project on IIS, but using a local profile in launchSetting.jsonOrganist
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.Hypogynous
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.Bant
W
18

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.

Whitethorn answered 22/10, 2018 at 15:42 Comment(2)
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: github.com/RealFaviconGenerator/realfavicongenerator/issues/372Mellott
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.Cornerstone
E
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
});
Epoch answered 24/12, 2018 at 13:36 Comment(0)
F
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.

Farandole answered 4/4, 2020 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.