【问题标题】:Regarding Session_End and Application_End methods in asp.net关于 asp.net 中的 Session_End 和 Application_End 方法
【发布时间】:2011-04-16 14:24:24
【问题描述】:

我正在尝试实现一个实现 System.Web.HttpApplication 接口的类(我们称之为 CustomerConnection 类)。我尝试通过这种方式在这个类中实现两个事件 session_end 和 application_end 事件:

public class CustomerConnection: System.Web.HttpApplication
{


    protected void Session_End(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        SqlConnection connection = context.Items[Database_Con] as SqlConnection;
        connection.close();

    }

    protected void Application_End(object sender, EventArgs e)
    {
        HttpApplication application = (HttpApplication)sender;
        HttpContext context = application.Context;
        //someotherEvent
    }

但似乎这些事件在应用程序结束或会话注销时都没有执行。

我应该如何让这些事件得到执行?是不是我必须通知某些其他事件?

我只是在创建一个新的客户类对象。是否足以执行这些事件或我的方法根本错误?

请帮帮我

感谢期待

【问题讨论】:

    标签: asp.net application-end sessionend


    【解决方案1】:

    你需要在 global.asax 中:

    <%@ Application Language="C#" Inherits="CustomerConnection"%>
    

    警告,我从未尝试过,我在这里找到了它:http://www.codedigest.com/Articles/ASPNET/34_Adding_CodeBehind_for_Gloabalasaz_x_file_in_aspnet_20.aspx

    【讨论】:

      【解决方案2】:

      您创建的对象没有连接到任何东西,因此它无法接收来自应用程序的任何事件。您必须将事件处理程序放在用于 Web 应用程序的对象中,即放在 Global.asax.cs 文件中。

      此外,没有Session_End 事件,它是Session_OnEnd

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-30
        • 2017-03-01
        • 2016-04-04
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多