c# – 如何从ASP.NET 4.0 Web应用程序禁用/删除WebPageHttpModule?

前端之家收集整理的这篇文章主要介绍了c# – 如何从ASP.NET 4.0 Web应用程序禁用/删除WebPageHttpModule?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图获得我的 wildcard http handler to handle *.cshtml pages,但请求从来没有到达我的处理程序,因为它被WebPageHttpModule拦截,我发现存在通过这个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

我已经尝试使用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 dll我只是引用System.Web.

那么这些程序集如何加载,为什么WebPageHttpModule被注册了,我该如何删除/禁用它?

解决方法

@H_403_19@ 如果您要关闭ASP.NET网页,可以在应用设置中设置此标志:
<add key="webpages:Enabled" value="false" />
原文链接:https://www.f2er.com/csharp/95450.html

猜你在找的C#相关文章