IIS 7.5 Unable to serve .cshtml files

I’m playing with WebMatrix and deploying my web site, but when I try to access it, I get the following error:

HTTP Error 404.17 – Not Found. The requested content appears to be script and will not be served by the static file handler.” 

After a bit of hunting around I found that the default .net framework associated with an Application Pool under IIS 7.x seems to be v2.0! To run a Razor site (and display .cshtml files) you must have .Net Framework v4.0 selected for the assigned application pool.

  • To do this, open up the IIS Manager Console (inetmgr.exe). 
  • Expand the hostname node in the “Connections” panel on the left hand side. 
  • Select the “Application Pools” node. 
  • All the App Pools will display in the centre pane, with their details, including which .Net Framework they are running.
  • If your site’s application pool is showing v2.0, double click it and change it to “v4.0 Integrated/Classic” (which ever you need) and then click the OK button to save it. 
  • With the app pool still selected in the main pane, click the “Recycle…” link in the “Actions” panel on the right hand side. This will ensure that the app pool is recycled and restarted with the correct .Net Framework loaded. 
  • Now go back to your website and reload your .cshtml file. It should appear as expected!