我正在尝试让我的通配符HTTP处理程序处理*.cshtml页面,但请求似乎从未到达我的处理程序,因为它似乎被WebPageHttpModule拦截了,我通过以下StackTrace发现了它的存在:
我已尝试使用Web.Config禁用所有HttpModules,但这没有任何效果(它也不会出现在IIS HttpModules部分):
使用ILSpy搜索发现,System.Web.WebPages.dll中的以下代码是注册WebPageHttpModule的代码:
[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
我已尝试使用Web.Config禁用所有HttpModules,但这没有任何效果(它也不会出现在IIS HttpModules部分):
<system.web>
<httpModules>
<clear/>
</httpModules>
</system.web>
....
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<clear/>
</modules>
</system.webServer>
使用ILSpy搜索发现,System.Web.WebPages.dll中的以下代码是注册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();
}
}
}
但这是一个纯粹的.NET 4.0应用程序,我没有引用任何System.Web.WebPages、MVC或Razor dlls,我只引用了System.Web。
那么这些程序集是如何被加载的,为什么WebPageHttpModule被注册,以及如何删除/禁用它?
.cshtml
结尾的URL仍然返回404错误。我正在尝试编写一个源代码浏览器,不能让它在任何URL扩展名上失败。有什么建议吗? - John Gietzen