Session_End事件中的Session变量的asp.net值 [英] asp.net values of Session variables in Session_End event

查看:124
本文介绍了Session_End事件中的Session变量的asp.net值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在会话变量中存储一个值

If I store a value in a session variable

    Session["Int"] = 100;

在Session_End事件中会有什么?是否为null或100?

What it will be in the Session_End event? Will it be null or 100?

void Session_End(object sender, EventArgs e)
{
      object objInt = Session["Int"];          // Null or 100 ?
}

意思是,Session_End会在会话中或之前处理所有内容之后, / p>

Meaning, will Session_End fire after disposing everything in the session or just before?

推荐答案

它是100.

要自己测试,只需添加ASP.NET应用程序文件 global.asax 到您的项目并处理 Session_Start end 会话结束 事件:

To test it yourself simply add the ASP.NET application file global.asax to your project and handle the Session_Start end Session-End events:

void Session_Start(object sender, EventArgs e)
{
   Session["Int"] = 100;          // 100
}

void Session_End(object sender, EventArgs e)
{
    object objInt = Session["Int"];  // it is still 100 here
}

你可以通过 Session.Abandon() (或到期时)。

You can end a Session by Session.Abandon() (or when it expires).

protected void Page_Load(object sender, EventArgs e)
{
    Session.Abandon();  // after this Session.End is called
}

这篇关于Session_End事件中的Session变量的asp.net值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆