Fix problem with CSHTML in IIS for webmatrix enabled pages in ASP.Net

In this post I will discuss how to serve .cshtml files from Windows 2003 server or IIS6. In general this discussion is applicable to IIS7/IIS7.5 on Windows 2007/Windows 2008 as well. Common symptom of problem is following error message.

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

Fundamental reason for this error is that you do not have WebMatrix or MVC framework not installed on your server. Now you can either install the framework that will install required assemblies in framework folder. Or you can copy necessary files in BIN folder of your application. Instead of trying to figure out what all files to copy, you can let Visual Studio 2010 help you with it. Here is simple procedure you can follow.

  • In Visual Studio 2010, right click on your web project and select Add Deployable Dependencies... option.

  • Now you will be presented with following dialog box. You can select option to copy Razor assemblies.

  • Now you will see a new folder _bin_deployableAssemblies in your web project in visual studio. Here you will see all the dependency assemblies in list. To get .cshtml file working on your server, you can remove the assemblies that are not required. You can trim down the list of assemblies to list as shown in image below.

    Removing of extra assemblies is going to be very important in certain cases because it can introduce some issues that can show up application load time. For example, I copied all webmatrix related files as well in bin folder and I ended up with following error in the application.

    Default Membership Provider could not be found

    After I deleted webmatrix files, application went back to normal.

Now when you publish your web application, you will have all the required files in BIN folder to server CSHTML files correctly.

Search

Social

Weather

26.1 °C / 78.9 °F

weather conditions Clear

Monthly Posts

Blog Tags