IIS Express (WebMatrix 2) won't serve .cshtml files in WebAPI project (VS10/WinXP)

帅比萌擦擦* 提交于 2020-01-03 02:51:05

问题


I am trying to run a WebAPI project on WinXP through WebMatrix 2. I'm getting this error when attempting to browse index.cshtml (in the root):

"This type of page is not served."

I created a WebAPI project under the MVC4 project type in Visual Studio 2010, then set the project to run under IIS Express.

What I've Tried:

The .NET CLR settings in the VS-created WebMatrix site is .NET 4.0 (Integrated).

I've already tried playing with the runAllManagedModulesForAllRequests setting in Web.config, no luck.

The error occurs in both the development server and IIS Express.

I have already rebooted.

However, if I create a Site through the WebMatrix2 UI, it works. Razor .cshtml files added to that site through WebMatrix render just fine.

TIA!


回答1:


SUCCESS!

The problem was a single line in the default WebAPI template web.config:

<appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />  <-- BAD!!!!
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

Setting that webpages:Enabled setting to true fixed the problem and now my .cshtml files work. Hope this helps others.

This question explains the webpages:Enabled setting: what is the function of webpages:Enabled in MVC 3 web.config



来源:https://stackoverflow.com/questions/12533605/iis-express-webmatrix-2-wont-serve-cshtml-files-in-webapi-project-vs10-winx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!