Search code examples
asp.netiisweb-configmime-types

How to I add a MIME type for a single specific file without extension in IIS?


I've been getting a lot of 404 notifications on the .well-known/traffic-advice location on my server. After doing some research it turns out the Chrome Privacy Preserving Prefetch Proxy tries to find instructions on prefetching content from the website.

I would like to add this file to give a proper response, but the file needs a specific MIME type: application/trafficadvice+json

In IIS it is easy to add a new MIME type for a specific extension, but in this case the 'traffic-advise' file has no extension. Also it's not advisable to specify a MIME type for all extension-less files.

How can I add the MIME type for this specific file in IIS (or web.config)?


Solution

  • As other solutions did not work for me, I used the following workaround to make it work:

    1. Add an extension to the file (/.well-known/traffic-advice) so it becomes traffic-advice.tdjson
    2. Add the MIME type for tdjson in web.config (or use IIS):
        <system.webServer>
          <staticContent>
            <mimeMap fileExtension=".tdjson" mimeType="application/trafficadvice+json" />
          </staticContent>
        </system.webServer>
    
    1. Install the URl rewrite module (https://www.iis.net/downloads/microsoft/url-rewrite)
    2. Add this rule to your Redirects.config file
        <rule name="wellknown trafficadvice" stopProcessing="true">
          <match url="^\.well-known\/traffic-advice$" ignoreCase="true" />
          <action type="Redirect" url="/.well-known/traffic-advice.tdjson" redirectType="Permanent" />
        </rule>
    
    1. Done