I'm trying to get my wildcard http handler to handle *.cshtml pages but the request never reaches my handler as it looks like it's being intercepted by WebPageHttpModule that I discovered exists via this StackTrace:
[HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.]
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application, Action`1 monitorFile, Func`2 fileExists, Func`2 createInstance, IEnumerable`1 supportedExtensions) +88
System.Web.WebPages.ApplicationStartPage.ExecuteStartPage(HttpApplication application) +287
System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application, Action`1 executeStartPage, EventHandler applicationStart) +113
System.Web.WebPages.WebPageHttpModule.StartApplication(HttpApplication application) +71
System.Web.WebPages.WebPageHttpModule.Init(HttpApplication application) +156
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +431
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +8972180
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
I've tried to disable all HttpModules using the Web.Config but this has no effect, (it also doesn't appear in IIS HttpModules section):
<system.web>
<httpModules>
<clear/>
</httpModules>
</system.web>
....
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<clear/>
</modules>
</system.webServer>
Hunting around with ILSpy reveals the following code in System.Web.WebPages.dll is what's registering the WebPageHttpModule:
namespace System.Web.WebPages
{
[EditorBrowsable(EditorBrowsableState.Never)]
public static class PreApplicationStartCode
{
private static bool _startWasCalled;
public static void Start()
{
if (PreApplicationStartCode._startWasCalled)
{
return;
}
PreApplicationStartCode._startWasCalled = true;
WebPageHttpHandler.RegisterExtension("cshtml");
WebPageHttpHandler.RegisterExtension("vbhtml");
PageParser.EnableLongStringsAsResources = false;
DynamicModuleUtility.RegisterModule(typeof(WebPageHttpModule));
ScopeStorage.CurrentProvider = new AspNetRequestScopeStorageProvider();
}
}
}
But it's a vanilla .NET 4.0 application and I don't have a references to any System.Web.WebPages, MVC or Razor dlls I'm only referencing System.Web.
So how are these assemblies getting loaded, why is WebPageHttpModule being registered and how can I remove/disable it?
.cshtml
I'm trying to write a source-code browser, and I cannot have it failing on any URL extension. Any suggestions? – Higley