Question

My NancyFX site, employing cshtml razor views, asp.net and IIS7, works just fine locally. It works via the VS12 built in 'ASP.NET Development Server' and also as a standalone site through my local copy of IIS7. I have ensured my web.config contains the correct razor sections.

If I deploy this site to a remote server (tested on my staging and live servers) then every URI returns the error:

406 - Client browser does not accept the MIME type of the requested page.

I have checked the Accept headers in the request. Here they are:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6

Other, non-nancy sites running on the remote servers work fine, they have exactly the same accept headers. This site used to work fine on the remote servers with the same Accept headers as far as I can tell.

I also did the following test on my staging server.

I renamed my HomeView.cshtml to HomeView.html and replaced all of its contents with hello world (no html tags, just the text). This was served without problems. I then renamed text-only HomeView.html back to HomeView.cshtml and got the 406 again.

Finally, and in desperation, I added a MIME type to the server that maps .cshtml -> text/html but of course it made no difference since I am not actually serving .cshtml files.

Why is Nancy (or perhaps IIS7) returning a 406 Not Acceptable response for any content derived from .cshtml files?

Edit Here is the nancy trace. It seems to show that either the HomeView.cshtml cannot be found or that the Razor View engine is not being used so any *.cshtml files will not be found.

Currently available view engine extensions: sshtml,html,htm

This then leads to the internal Nancy exception:

Nancy.ViewEngines.ViewNotFoundException

Yet precisely the same site files run locally and do invoke the Razor View engine correctly and hence find HomeView.cshtml.

I am still stumped.

_Nancy Trace

[StaticContentConventionBuilder] The requested resource '/home' does not match convention mapped to '/Content'
[DefaultRouteResolver] Found exact match route
[DefaultRouteInvoker] Processing as negotiation
[DefaultRouteInvoker] Accept header: text/html;q=1, application/xhtml+xml;q=1, application/xml;q=0.9, */*;q=0.8
[DefaultRouteInvoker] Acceptable media ranges: text/html
[DefaultRouteInvoker] Invoking processor: Nancy.Responses.Negotiation.ViewProcessor
[DefaultViewFactory] Rendering view with name HomeView
[DefaultViewResolver] Resolving view for 'HomeView', using view location conventions.
[DefaultViewResolver] Attempting to locate view using convention 'views/Home/HomeView'
[DefaultViewResolver] Attempting to locate view using convention 'Home/HomeView'
[DefaultViewResolver] Attempting to locate view using convention 'views/HomeView'
[DefaultViewResolver] Attempting to locate view using convention 'HomeView'
[DefaultViewResolver] No view could be resolved using the available view location conventions.
[DefaultViewFactory] Unable to find view engine that could render the view.
[DefaultRouteInvoker] Processor threw Nancy.ViewEngines.ViewNotFoundException exception: Unable to locate view 'HomeView'
Currently available view engine extensions: sshtml,html,htm
Locations inspected: ,views/Home/HomeView,,Home/HomeView,views/HomeView,HomeView
Root path: D:\wwwroot\GoodPractice.uMentor\[DefaultRouteInvoker] Invoking processor: Nancy.Responses.Negotiation.ViewProcessor
[DefaultViewFactory] Rendering view with name HomeView
[DefaultViewResolver] Resolving view for 'HomeView', using view location conventions.
[DefaultViewResolver] Attempting to locate view using convention 'views/Home/HomeView'
[DefaultViewResolver] Attempting to locate view using convention 'Home/HomeView'
[DefaultViewResolver] Attempting to locate view using convention 'views/HomeView'
[DefaultViewResolver] Attempting to locate view using convention 'HomeView'
[DefaultViewResolver] No view could be resolved using the available view location conventions.
[DefaultViewFactory] Unable to find view engine that could render the view.
[DefaultRouteInvoker] Processor threw Nancy.ViewEngines.ViewNotFoundException exception: Unable to locate view 'HomeView'
Currently available view engine extensions: sshtml,html,htm
Locations inspected: ,views/Home/HomeView,,Home/HomeView,views/HomeView,HomeView
Root path: D:\wwwroot\GoodPractice.uMentor\[DefaultRouteInvoker] Unable to negotiate response - no processors returned valid response
Was it helpful?

Solution

The answer was simple. I just needed to

  • uninstall the Nancy.Viewengines.Razor package (NuGet)
  • install the Nancy.Viewengines.Razor package (NuGet)
  • Clean the project
  • Recompile
  • Redeploy

Voila! I should have done that 16 hours ago I reckon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top