What exactly needs done to IIS 6 to serve cshtml p

2019-01-15 00:48发布

问题:

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.

回答1:

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:

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.



回答3:

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


回答4:

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.



回答5:

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.



标签: iis-6 razor