1

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.

Community
  • 1
  • 1
erdomke
  • 4,980
  • 1
  • 24
  • 30

2 Answers2

3

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)
erdomke
  • 4,980
  • 1
  • 24
  • 30
1

Here's a link to the Rackspace knowledge center that shows how to change the MIME mapping for static content in the web.config file.

https://www.iis.net/configreference/system.webserver/staticcontent/mimemap

There's also this one from MS that's more in-depth.

https://www.iis.net/configreference/system.webserver/staticcontent/mimemap

They both feature this stanza from the web.config file.

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

If that's how to actually fix the 406.0 problem...

ourmandave
  • 1,505
  • 2
  • 15
  • 49
  • No luck with that. `` did not stop the error, nor did the `` that I had previously. – erdomke Nov 19 '15 at 13:48
  • @erdomke You could try this [config setting](https://github.com/NancyFx/Nancy/wiki/Managing%20static%20content#letting-iis-handle-static-content) to stop Nancy from processing .xml files. – ourmandave Nov 19 '15 at 14:35
  • @erdomke Also at the bottom of (this page)[https://github.com/NancyFx/Nancy/wiki/View-engines) is this sentence. `As part of the new [Content Negotiation](https://github.com/NancyFx/Nancy/wiki/Content%20Negotiation) features in 0.12, if Nancy could not find your view, the server will return 406 Not Acceptable instead.` Maybe turn on tracing and see what it's not finding? – ourmandave Nov 19 '15 at 14:49
  • Thanks for the additional help. Unfortunately, I don't think that either of the suggestions are the answer. (1) I actually do want Nancy to process this request and want to bypass whatever IIS is trying to do for me. (2) I added a screenshot to the answer which shows that this is an IIS error and not a Nancy error. I also am not currently using Content Negotiation. – erdomke Nov 19 '15 at 15:36