I happened upon this question while trying to solve the same problem - although in my case, for curiosity's sake.
Here's what you need in your web.config file:
<system.web>
<compilation>
<buildProviders>
<add extension=".html"
type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
</buildProviders>
</compilation>
</system.web>
<system.webServer>
<handlers>
<add name="Html" verb="*" path="*.html"
type="System.Web.Webpages, WebPageHttpHandler"/>
</handlers>
</system.webServer>
This isn't enough on its own, though! We need to register the extension with WebPageHttpHandler
.
Normally, you'd be able to do stuff like this in the _AppStart
file - unfortunately, when the application starts (i.e when _AppStart
executes), it iterates over the items in the SupportedExtensions of WebPageHttpHandler, so we can't actually register the extension in AppStart.
What I did is I made a new .dll assembly with the PreApplicationStartMethod
attribute, as seen here, but you can also do it inside the Global.asax
file's Application_Start
method.
Finally, we also need to add "html" as an extension to the RazorCodeLanguage.Languages
dictionary, so that the Razor engine can figure out how to compile the template.
Example Global.asax file:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
System.Web.WebPages.WebPageHttpHandler.RegisterExtension("html");
var languages = System.Web.Razor.RazorCodeLanguage.Languages;
languages.Add("html", languages["cshtml"]);
}
</script>