Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly needs done to IIS 6 to serve cshtml pages?

Tags:

razor

iis-6

I have upgraded my site to .Net4 but when requesting a .cshtml file (even if it is pure html without razor) I get a Connection refused error. What's missing?

Update: something changed and now I get a "This type of page is not served" error. I thought .Net4 was all that was required.

like image 344
Graeme Avatar asked May 05 '11 15:05

Graeme


2 Answers

Turns out it was simply a matter of having the correct files in the bin dir and an entry in web config. Here's the list of files:

  • Microsoft.Web.Infrastructure.dll
  • NuGet.Core.dll
  • System.Web.Helpers.dll
  • System.Web.Razor.dll
  • System.Web.WebPages.Administration.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll

and here's what I needed in web.config:

<compilation>
  <assemblies>
    <add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
  <buildProviders>
    <add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
  </buildProviders>
</compilation>
like image 197
Graeme Avatar answered Nov 29 '22 10:11

Graeme


In addition to .NET 4.0 you need to have the correct .dlls for razor. If you have Visual Studio 2010 SP1 installed you can right click on your web project and select Add Deployable Dependencies. This will copy the required .dlls to you bin folder when you publish your site. If you haven't got SP1 installed you will need to manually configure the .dlls to be published. This post has a good write up of hw to do it.

like image 37
Adam Flanagan Avatar answered Nov 29 '22 10:11

Adam Flanagan