pee2pee
pee2pee

Reputation: 3802

C# and Razor - The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect

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

<?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

Upvotes: 13

Views: 37102

Answers (6)

jetpilot
jetpilot

Reputation: 47

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.

Upvotes: 1

XDS
XDS

Reputation: 4206

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.

Upvotes: 1

Arjan Einbu
Arjan Einbu

Reputation: 13692

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

Upvotes: 8

Daniel Williams
Daniel Williams

Reputation: 9314

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

Upvotes: 6

Edyn
Edyn

Reputation: 2497

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

Upvotes: 1

user1449936
user1449936

Reputation: 21

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.

Upvotes: 2

Related Questions