IIS Express (WebMatrix 2) won't serve .cshtml

2019-05-29 18:52发布

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):

notservederror

"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条回答
乱世女痞
2楼-- · 2019-05-29 19:32

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

查看更多
登录 后发表回答