关于asp.net中的Session_End和Application_End方法

发布于 2024-11-01 22:36:01 字数 880 浏览 0 评论 0原文

我正在尝试实现一个实现 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
    }

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

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

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

请帮帮我

谢谢期待

I'm trying to implement a class (lets call it CustomerConnection class) which implements System.Web.HttpApplication interface. I tried to implement two events session_end and application_end events in this class in this way:

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
    }

But it seems these events are not getting executed neither for the application end or session log out.

How should i make these events get´executed ? Is it like i have to notify to certain other event?

I'm just creating a new object of customer class. is it enough to get these events executed or my approach is fundamentally wrong?

Please help me out

Thanks in anticipation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

筱果果 2024-11-08 22:36:01

你需要在global.asax中使用这个:

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

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

You need this in global.asax:

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

Caveat, I've never tried this, I found it here: http://www.codedigest.com/Articles/ASPNET/34_Adding_CodeBehind_for_Gloabalasaz_x_file_in_aspnet_20.aspx

空‖城人不在 2024-11-08 22:36:01

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

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

The object that you have created isn't connected to anything, so it can't receive any events from the application. You have to put the event handlers in the object that is used for the web application, i.e. in the Global.asax.cs file.

Besides, there is no Session_End event, it's Session_OnEnd.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文