Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在何处实现Global.asax方法_C#_Asp.net_Vb.net_Global Asax - Fatal编程技术网

C# 在何处实现Global.asax方法

C# 在何处实现Global.asax方法,c#,asp.net,vb.net,global-asax,C#,Asp.net,Vb.net,Global Asax,我正在使用ASP.Net应用程序,目前Global.asax包含常用的5种方法: 应用程序启动 应用程序结束 会话(u)开始 会议结束 应用程序错误 但是,我还需要实现Application\u AuthenticateRequest方法,这不是问题,我刚刚在Global.asax中添加了它,但在另一个应用程序中,我看到该方法在实现IHttpModule接口的另一个类的其他地方实现 这怎么可能?同一应用程序在Global.asax中没有应用程序\u AuthenticateRequest,其Gl

我正在使用ASP.Net应用程序,目前Global.asax包含常用的5种方法:

  • 应用程序启动
  • 应用程序结束
  • 会话(u)开始
  • 会议结束
  • 应用程序错误
  • 但是,我还需要实现
    Application\u AuthenticateRequest
    方法,这不是问题,我刚刚在Global.asax中添加了它,但在另一个应用程序中,我看到该方法在实现
    IHttpModule
    接口的另一个类的其他地方实现

    这怎么可能?同一应用程序在Global.asax中没有
    应用程序\u AuthenticateRequest
    ,其Global.asax如下所示:

    void Application_BeginRequest(object sender, EventArgs e)
    {
        myConfig.Init();
    }
    
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        myConfig.Init();
        if (InstallerHelper.ConnectionStringIsSet())
        {
            //initialize IoC
            IoC.InitializeWith(new DependencyResolverFactory());
    
            //initialize task manager
            TaskManager.Instance.Initialize(NopConfig.ScheduleTasks);
            TaskManager.Instance.Start();
        }
    }
    
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        if (InstallerHelper.ConnectionStringIsSet())
        {
            TaskManager.Instance.Stop();
        }
    }
    
    public class MembershipHttpModule : IHttpModule
    {
        public void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            // Fires upon attempting to authenticate the user
            ...
        }
    
        public void Dispose()
        {
        }
    
        public void Init(HttpApplication application)
        {
            application.AuthenticateRequest += new EventHandler(this.Application_AuthenticateRequest);
        }
    }
    

    是什么使
    应用程序\u AuthenticateRequest
    方法运行?

    我首先建议您阅读。然后您就会知道,在ASP.NET应用程序中,您可以注册多个模块,这些模块将为每个请求运行,并且您可以订阅请求生命周期中的不同事件,就像您在Global.asax中那样。这种方法的优点是,您可以将模块放入一个可重用的程序集中,在多个应用程序中使用,从而避免重复相同的代码。

    我首先建议您阅读。然后您就会知道,在ASP.NET应用程序中,您可以注册多个模块,这些模块将为每个请求运行,并且您可以订阅请求生命周期中的不同事件,就像您在Global.asax中那样。这种方法的优点是,您可以将模块放入一个可重用的程序集中,在多个应用程序中使用,从而避免重复相同的代码。

    基本上,我所看到的示例创建了自己的HTTP模块,并将其注册到web.config文件中:

    他们创建了一个新的HTTP模块,如下所示:

    void Application_BeginRequest(object sender, EventArgs e)
    {
        myConfig.Init();
    }
    
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        myConfig.Init();
        if (InstallerHelper.ConnectionStringIsSet())
        {
            //initialize IoC
            IoC.InitializeWith(new DependencyResolverFactory());
    
            //initialize task manager
            TaskManager.Instance.Initialize(NopConfig.ScheduleTasks);
            TaskManager.Instance.Start();
        }
    }
    
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        if (InstallerHelper.ConnectionStringIsSet())
        {
            TaskManager.Instance.Stop();
        }
    }
    
    public class MembershipHttpModule : IHttpModule
    {
        public void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            // Fires upon attempting to authenticate the user
            ...
        }
    
        public void Dispose()
        {
        }
    
        public void Init(HttpApplication application)
        {
            application.AuthenticateRequest += new EventHandler(this.Application_AuthenticateRequest);
        }
    }
    
    还将以下内容添加到web.config文件:

    <httpModules>
      <add name="MembershipHttpModule" type="MembershipHttpModule, App_Code"/>
    </httpModules>   
    
    
    
    上图:必须注册模块才能从请求管道接收通知。注册HTTP模块最常用的方法是在应用程序的Web.config文件中。在IIS 7.0中,统一请求管道还允许您以其他方式注册模块,包括通过IIS管理器和Appcmd.exe命令行工具。基本上,我所看到的示例创建了自己的HTTP模块并将其注册到web.config文件中:

    他们创建了一个新的HTTP模块,如下所示:

    void Application_BeginRequest(object sender, EventArgs e)
    {
        myConfig.Init();
    }
    
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        myConfig.Init();
        if (InstallerHelper.ConnectionStringIsSet())
        {
            //initialize IoC
            IoC.InitializeWith(new DependencyResolverFactory());
    
            //initialize task manager
            TaskManager.Instance.Initialize(NopConfig.ScheduleTasks);
            TaskManager.Instance.Start();
        }
    }
    
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        if (InstallerHelper.ConnectionStringIsSet())
        {
            TaskManager.Instance.Stop();
        }
    }
    
    public class MembershipHttpModule : IHttpModule
    {
        public void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            // Fires upon attempting to authenticate the user
            ...
        }
    
        public void Dispose()
        {
        }
    
        public void Init(HttpApplication application)
        {
            application.AuthenticateRequest += new EventHandler(this.Application_AuthenticateRequest);
        }
    }
    
    还将以下内容添加到web.config文件:

    <httpModules>
      <add name="MembershipHttpModule" type="MembershipHttpModule, App_Code"/>
    </httpModules>   
    
    
    
    上图:必须注册模块才能从请求管道接收通知。注册HTTP模块最常用的方法是在应用程序的Web.config文件中。在IIS 7.0中,统一请求管道还允许您以其他方式注册模块,包括通过IIS管理器和Appcmd.exe命令行工具。

    谢谢,在阅读了有关HTTP模块的信息后,事情变得更清楚了。谢谢,在阅读了有关HTTP模块的信息后,事情变得更清楚了。