I have added the lines to the web.config to make .html files handled by the pagehandlerfactory – but it isn’t working when I publish the site to a live web host. It works on my development box (Not using IIS), but I don’t have any other options on my live to add anything… It’s a shared hosting environment.
What should I try to do? I don’t get any errors, so I know it can’t be because of the root web.config overwriting.
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
</buildProviders>
</compilation>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
<add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*.html" type="System.Web.UI.PageHandlerFactory" />
Then in the HTML page…
<%@ Page Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.Page" %>
…
<% Response.Write(“Testing. This is content written by ASP.NET.”); %>
The most likely problem is that IIS isn’t configured to route requests for .html files through ASP.NET.
Check your web site’s IIS properties, Home Directory Tab, Configuration… button, Mappings tab.
At the top you’ll see a list of file extensions and what the handler for that extension is. Anything that’s not in that list will just be served as a flat file, which is more efficient on heavy load rather than loading the ASP.NET environment only to then just write a file out to the response.
So the solution is basically just to add .html/.htm to the list, and copy the settings from one of the other ones like .aspx
The reason I suspect this worked on your development machine is that you ran the website from the debugger rather than through IIS. The debugger processes all requests, rather than the more complicated handling of IIS.
Note that this is all IIS 6 and below information — things are a bit different if you’re on IIS 7.