问题
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