Disabling .cshtml extension

Jun 25, 2011 at 8:12 PM

Hi,

Does anyone know how to disable the .cshtml extension completely from an ASP.NET Web Application?

I want to try hijack the .cshtml extension to provide my own implementation based on RazorEngine, but when I try to access the page.cshtml directly it appears that 

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>
		<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"/>
		<handlers>
			<clear/>
			<add path="*" name="MyHandler" type="MyHandler" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
		</handlers>
	</system.webServer>

But no matter what I do, when I visit any page.cshtml page it bypasses My wildcard handler completely and looks like its running the .cshtml page under the System.Web.WebPages.Razor context seeing that 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

Basically I want to remove all traces of .cshtml handlers/preprocessing so I can serve the .cshtml pages myself, anyone know how to do this?

Coordinator
Jun 27, 2011 at 3:04 PM

Have you removed it using the

ViewEngines.Engines.Clear();


 

You'll have to add back the ViewEngines you want to use such as the WebFormsViewEngine. But that should remove ".cshtml"