Web Server not serving certain file types

Internet Information Services (IIS, formerly Internet Information Server) will not return file types that are not added to the <staticContent> element or that have mappings in the <handlers> element by default.

This behavior prevents unauthorized access to files that do not have mappings in the IIS configuration settings.

The message returned is:

“The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.”

Fix this issue by adding a mime type to the web server or application. To add to the application, make a web.config file and place it on your root folder.

In this example, I added mime types for SVG, TTML, VTT and WOFF files, which I use in a Chromecast receiver application:

web.config

<configuration>
   <system.webServer>
      <staticContent>
         <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
         <mimeMap fileExtension=".ttml" mimeType="application/ttml+xml" />
         <mimeMap fileExtension=".vtt" mimeType="text/vtt" />
         <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      </staticContent>
   </system.webServer>
</configuration>

Sometimes your browser might display this message back for a response:

“The page cannot be displayed because an internal server error has occurred”

When this happens, make sure you tell the server to remove the map before adding it. This will usually happens with file types like XML that are listed on IIS by default:

<configuration>
   <system.webServer>
      <staticContent>
         <remove fileExtension=".xml" />
         <mimeMap fileExtension=".xml" mimeType="application/xml" />
      </staticContent>
   </system.webServer>
</configuration>

To learn more, go to the IIS website. And happy coding!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s