Session的定义与使用

以前用Session的时候,总是拿来就用,也没想过先定义再使用,今天就换一种方式。

private void Button1_Click(object sender, System.EventArgs e)
{
System.Web.SessionState.HttpSessionState session = System.Web.HttpContext.Current.Session;//
创建Session
session.Add("test","Test Session");//Session赋值
session.Timeout = 10;//设置会话超时期限,单位为分钟
this.TextBox1.Text = System.Web.HttpContext.Current.Session["test"].ToString();
}

人的一生应该这样度过:当他回首往事的时候,不会因为虚度年华而悔恨,也不会因为碌碌无为而羞愧。
原文地址:https://www.cnblogs.com/htht66/p/916167.html