当NancyFX站点尝试服务器剃刀视图时,406响应

时间:2012-10-03 15:35:14

标签: razor nancy http-status-code-406

我的NancyFX网站,使用cshtml razor视图,asp.net和IIS7,在本地工作得很好。它通过内置在“ASP.NET Development Server”中的VS12工作,也可以通过IIS7的本地副本作为独立站点工作。我确保我的web.config包含正确的剃刀部分。

如果我将此站点部署到远程服务器(在我的登台和实时服务器上测试),那么每个URI都会返回错误:

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

我已检查了请求中的Accept标头。他们在这里:

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

在远程服务器上运行的其他非南希站点工作正常,它们具有完全相同的接受标头。据我所知,这个站点曾经在远程服务器上使用相同的Accept标头正常工作。

我还在我的登台服务器上进行了以下测试。

我将HomeView.cshtml重命名为HomeView.html,并将所有内容替换为hello world(没有html标记,只有文本)。这没有问题。然后我将仅文本HomeView.html重命名为HomeView.cshtml并再次获得406。

最后,在绝望中,我向映射.cshtml - >的服务器添加了MIME类型。 text/html但当然没有区别,因为我实际上并没有提供.cshtml个文件。

为什么Nancy(或者IIS7)对从406 Not Acceptable文件派生的任何内容返回.cshtml响应?

修改 这是南希的踪迹。它似乎表明无法找到HomeView.cshtml或者没有使用Razor View引擎,因此找不到任何 * .cshtml文件。

Currently available view engine extensions: sshtml,html,htm

然后导致内部Nancy例外:

Nancy.ViewEngines.ViewNotFoundException

然而,正好相同的站点文件在本地运行并且正确地调用Razor View引擎,因此找到HomeView.cshtml

我仍然难过。

_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

1 个答案:

答案 0 :(得分:2)

答案很简单。我只需要

  • 卸载Nancy.Viewengines.Razor包(NuGet)
  • 安装Nancy.Viewengines.Razor包(NuGet)
  • 清理项目
  • 重新编译
  • 重新部署

瞧! 16小时前我应该这样做,我估计。

相关问题