Search code examples
asp.netiisweb-confignancyhttp-status-code-406

How do I bypass Accept header validation in IIS?


I have a Nancy website hosted on ASP.Net with a number of custom routes. These routes include mappings which look like file paths (e.g. /path/to/xml_file.xml), but that resolve to HTML files which should display in the browser. For most files, this works correctly. However, with XML files (and possibly other mime types), I am getting a 406.0 HTTP error from IIS 8 Express explicitly stating that

HTTP Error 406.0 - Not Acceptable

The resource cannot be displayed because the file extension is not being accepted by your browser.

The request was rejected because it contained an Accept header for a MIME type that is not supported for the requested file extension.

Verify the MIME settings for the file extension that was requested to make sure this MIME type is acceptable.

406 Error Page Screenshot

Is there any web.config setting or other technique for bypassing this validation so that I don't get this error without having to rewrite the path logic? My Google searching is failing me. For example, I have found this IIS forum post linked from the SO Answer which talks about

map all reqests to ASP.NET and use the ASP.NET's StaticFileHandler to serve them

However, the post does not explain how to do this; nor does it seem applicable.

Edit: (Added error page image above)

As another tidbit, the Nancy route returns an explicit view of the form

return View["view_name", myModel];

And therefore, should bypass content negotiation.


Solution

  • While not a fix or answer per se, my current work around (for anyone who might be interested) is to tweak the routes to use a trailing slash. As an example:

    "/path/to/xml_file.xml"   //  Still returns a 406.0 error
    "/path/to/xml_file.xml/"  //  Works properly (notice the trailing slash)