1

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!

Community
  • 1
  • 1
Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
  • What's the error? There might be an image that I can't see (might be blocked?) – SpaceBison Sep 21 '12 at 15:37
  • @SpaceBison Updated the question with the error. – Dave Swersky Sep 21 '12 at 15:38
  • http://stackoverflow.com/questions/5111625/iis-express-fails-to-serve-cshtml-files - could be same issue as this with previous version of webmatrix – SpaceBison Sep 21 '12 at 15:41
  • @SpaceBison Thanks, I've been up and down that question, it doesn't help me. The OP is using Win7, I'm on WinXP. – Dave Swersky Sep 21 '12 at 15:42
  • Is there an applicationHost.config for IISExpress running under WebMatrix? IsapiModule definitions in my own dev applicationHost.config (running under VS2010) point cshtm/cshtml/vbhtm/vbhtml to System.Web.HttpForbiddenHandler, perhaps it's the default behaviour? You no doubt already have been over all this.... – SpaceBison Sep 21 '12 at 15:50
  • @SpaceBison thanks for the applicationHost suggestion, it led me to the answer! – Dave Swersky Sep 21 '12 at 17:14

1 Answers1

9

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

Community
  • 1
  • 1
Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
  • cshtml files are not meant to be viewed directly. They should be returned through the controller action (e.g. http://localhost:6068/People/Index) – Peter Munnings Oct 09 '12 at 13:25
  • 1
    @Peter that is true for MVC projects, but not for non-MVC projects using Razor syntax. I'm learning to build a Single Page Application. – Dave Swersky Oct 09 '12 at 15:05
  • Thanks for that feedback - then you have exactly the correct solution – Peter Munnings Oct 10 '12 at 05:47
  • Good spot as this is a tricky one to troubleshoot. Razor pages stopped working after I copied some files from an MVC project to a WebForms project. I removed the "BAD!" setting and was going again. Up Vote. – Yogi May 05 '18 at 23:30