9

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.

5 Answers 5

8

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>
2
  • This is what known as a bin deploy from the look of it. to get the server working without doing this you will need to install MVC 3.0
    – TheAlbear
    May 10, 2011 at 9:27
  • Also I have to add the .cshtml to the application extensions in the IIS. Aug 6, 2013 at 17:39
3

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.

1
  • Saw this answer after I posted mine. Thanks - the links basically confirm the conclusion I came to, though I found I also needed NuGet.Code.dll for some strange reason. And the links don't mention the web.config entry that my deploy required.
    – Graeme
    May 6, 2011 at 8:55
2

Check out this post.

  1. Open IIS Manager
  2. Right click on your site --> Manage Web Site --> Advanced Settings
  3. Note down the application pool being used and cancel 'Advnaced settings' dialog
  4. Now Select 'Application pools' in the left navigation bar and double click the application pool noted in step 3 and change .net framework version to 4.0
1
  • 1
    Very helpful, indeed! I would recommend to add a new pool for the application instead of changing the existing pool's settings as the existing pool may be shared with other applications.
    – SaschaM78
    Oct 16, 2018 at 8:33
2

For me, getting IIS 8 to serve .cshtml pages was simply a matter of selecting the right Windows Features to install on Windows 8.

From the control panel, search for "features". Then click on "Turn Windows features on or off". Of course, you have to have "Internet Information Services checked (installed). I think you also need to consider checking:

  • Internet Information Services / Application Development Features / .NET Extensibility 4.5
  • Internet Information Services / Application Development Features / ASP.NET 4.5
  • Internet Information Services / Application Development Features / ISAPI Extensions
  • Internet Information Services / Application Development Features / ISAPI Filters
  • Internet Information Services / Application Development Features / Server-Side Includes

I might have included an extra feature. I know I left out some nice-to-haves such as logging and tracing to help debug.

If IIS still does not serve the Razor Syntax pages (.cshtml), then look for more IIS features to install because I think ALL I had to do was pick the right IIS features.

Another mistake I made was in setting up the binding for the website, I thought I should put a name in the Host box. But this makes IIS go out to the Internet to that web site, if it can find it. So, for a simple setup, leave Host blank. The website name is handled elsewhere. And that elsewhere is the Domain Name Server (DNS) at your domain name registrar.

So, this answer might help in addition to considering the other answers.

1

It should be fixed by applying the right application pool as stated by Danny, Make sure that you are not running any .Net 2 /3/3.5 sites on the new .Net 4.0 app pool or you will get an error. I would recommend making a new .Net 4.0 app pool then setting your new site to this.

Oh getting IIS6 to run .net 4 you need to follow this guide.

There is also the possibility that the file type is not known by IIS. In that case you will need to add it to the mappings (this also allows you to make custom extensions).

Select your website > Home Directory > Configuration (Button) > and then insert a new mapping. map .cshtm to c:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll limit to GET,HEAD,POST,DEBUG

If you need to add the mapping mostly the install of .net 4 hasn't worked properly and you will need to add all the mappings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.