12

I have looked through other posts but none seem to answer what I need.

  • I created an empty site in WebMatrix (ASP.NET)
  • I opened that site in VWD 2013
  • I hit F5 and it runs fine on a URL such as http://local.com:59833/ContentPage.cshtml
  • I go to http://local.com/cscsu_bi/ContentPage.cshtml and it doesn't work with the error below

    Server Error in '/' Application.

    This type of page is not served.

    Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.

    Requested URL: /cscsu_bi/ContentPage.cshtml

  • The web.config file is as follows

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
    <add key="webpages:Enabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
</configuration>

I am on Windows 7. Is there anything obvious I'm doing wrong?

Thanks

pee2pee
  • 3,619
  • 7
  • 52
  • 133
  • Did you try with `html` extension ? – Ofiris Mar 07 '14 at 10:52
  • Looks like you're attempting to navigate to the physical path to the file, you have to use the virtual path (which is the first one you list) – Alex Mar 07 '14 at 13:14
  • In Razor (your tag) your controllers should be executing actions based on a path such as `/controllername/actioname/id`. cshtml files are used for controller's views and not be accessed directly. Are you trying to use cshtml files as if they are ASPX files? – iCollect.it Ltd Mar 09 '14 at 21:30
  • http://www.asp.net/web-pages/tutorials/introducing-aspnet-web-pages-2/getting-started you can access them directly – pee2pee Mar 10 '14 at 08:48

6 Answers6

8

I was missing the Microsoft.AspNet.WebPages NuGet package. Installing it solved my problem. (This package has dependencies on Microsoft.Web.Infrastructure and Microsoft.Web.Razor and thus includes them for you)

If you use the NuGet console, just type:

Install-Package Microsoft.AspNet.WebPages
Arjan Einbu
  • 13,543
  • 2
  • 56
  • 59
5

I have set up Razor on a number of machines, and often find that I need to include the following DLLs in my bin folder:

  • System.Web.Razor.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll
  • Microsoft.Web.Infrastructure.dll
Daniel Williams
  • 8,912
  • 15
  • 68
  • 107
1

Take a look at this article.

http://www.asp.net/web-pages/overview/more-resources/aspnet-web-pages-(razor)-troubleshooting-guide

This fixed my issue after reviewing all IIS settings and references.

Make sure that the root of your website has at least one .cshtml file in it.

1

This may not be your exact issue, but I have had this happen for a couple reasons:

  1. Incorrect Framework on Server: Make sure the target framework of the project is supported by the server. Just changing the targetFramework attribute of the compilation element may not be enough as the DLLs for your project may be compiled against the 4.5 framework.

  2. Incorrect Framework of Application Pool: This can also happen if your application pool is not using the right .Net CLR version. Make sure it is using the 4.0 instead of 2.0

Edyn
  • 2,409
  • 2
  • 26
  • 25
1

In my case the culprit was the fact that Global.asax was placed under the '/Views' folder. This was somehow working while the project was targeting MVC3. Once the solution got upgraded to MVC4, running said solution would result in the aforementioned errors. In a similar vein, other errors would crop up mentioning:

"no default webpage has been set and directory browsing has been disabled"

The solution: After upgrading to MVC4+ I had to manually move Global.asax under the root folder of the container project. Be sure to inspect Global.asax to make sure that the namespace applied within is the proper one. Just my 2c.

XDS
  • 3,786
  • 2
  • 36
  • 56
1

In my case I set webpages:Enabled to true under appSettings:

<appSettings>
  <add key="webpages:Enabled" value="false" />
</appSettings>   

According to post: what is the function of webpages:Enabled in MVC 3 web.config, this prevents files in the Views folder from being directly accessible from a web browser.

anothernode
  • 5,100
  • 13
  • 43
  • 62
jetpilot
  • 47
  • 6