我的 NancyFX 站点使用 cshtml razor 视图、asp.net 和 IIS7,在本地运行良好。它通过内置在“ASP.NET 开发服务器”中的 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
在远程服务器上运行的其他非 nancy 站点工作正常,它们具有完全相同的接受标头。据我所知,该站点曾经在具有相同 Accept 标头的远程服务器上正常工作。
我还在我的登台服务器上做了以下测试。
我将我的重命名HomeView.cshtml
为HomeView.html
并将其所有内容替换为hello world
(没有 html 标签,只有文本)。这服务没有问题。然后我将纯文本重命名HomeView.html
为HomeView.cshtml
并再次获得 406。
最后,在绝望中,我向映射的服务器添加了一个 MIME 类型.cshtml
->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
.
我仍然很难过。
_南希追踪
[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