关于asp.net中的Session_End和Application_End方法
我正在尝试实现一个实现 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要在global.asax中使用这个:
警告,我从来没有尝试过这个,我在这里找到它: http://www.codedigest.com/Articles/ASPNET/34_Adding_CodeBehind_for_Gloabalasaz_x_file_in_aspnet_20.aspx
You need this in global.asax:
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
您创建的对象未连接到任何东西,因此它无法接收来自应用程序的任何事件。您必须将事件处理程序放在用于 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'sSession_OnEnd
.