I have looked through other posts but none seem to answer what I need.
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
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.
This may not be your exact issue, but I have had this happen for a couple reasons:
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.
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
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.
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:
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.