Disable Razors default .cshtml handler in a ASP.NET Web Application
Posted
by
mythz
on Stack Overflow
See other posts from Stack Overflow
or by mythz
Published on 2011-06-25T19:20:35Z
Indexed on
2011/06/27
8:22 UTC
Read the original article
Hit count: 618
Does anyone know how to disable the .cshtml extension completely from an ASP.NET Web Application?
In essence I want to hijack the .cshtml extension and provide my own implementation based on a RazorEngine host, although when I try to access the page.cshtml directly it appears to be running under an existing WebPages razor host that I'm trying to disable.
Note: it looks like its executing .cshtml pages under the System.Web.WebPages.Razor context as the Microsoft.Data Database is initialized. I don't even have any Mvc or WebPages dlls referenced, just System.Web.dll and a local copy of System.Web.Razor with RazorEngine.dll
I've created a new ASP.NET Web .NET 4.0 Application and have tried to clear all buildProviders and handlers as seen below:
<system.web>
<httpModules>
<clear/>
</httpModules>
<compilation debug="true" targetFramework="4.0">
<buildProviders>
<clear/>
</buildProviders>
</compilation>
<httpHandlers>
<clear/>
<add path="*" type="MyHandler" verb="*"/>
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<clear/>
</modules>
<handlers>
<clear/>
<add path="*" name="MyHandler" type="MyHandler" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
Although even with this, when I visit any page.cshtml page it still bypasses My wildcard handler and tries to execute the page itself.
Basically I want to remove all traces of .cshtml handlers/buildProviders/preprocessing so I can serve the .cshtml pages myself, anyone know how I can do this?
© Stack Overflow or respective owner