private string mySessionKey
{
get
{
if (ViewState["MySession"] == null)
{
Guid guid = Guid.NewGuid();
ViewState["MySession"] = guid.ToString();
return guid.ToString();
}
else
{
return ViewState["MySession"].ToString();
}
}
}
/// <summary>
/// 相当于ViewState用 记得离开页面的时候清除一下///
/// </summary>
protected Hashtable MySession
{
get
{
Hashtable ht = Session[mySessionKey] as Hashtable;
if (ht == null)
{
ht = new Hashtable();
Session[mySessionKey]=ht;
}
return ht;
}
set
{
Session[mySessionKey] = value;
}
}
{
get
{
if (ViewState["MySession"] == null)
{
Guid guid = Guid.NewGuid();
ViewState["MySession"] = guid.ToString();
return guid.ToString();
}
else
{
return ViewState["MySession"].ToString();
}
}
}
/// <summary>
/// 相当于ViewState用 记得离开页面的时候清除一下///
/// </summary>
protected Hashtable MySession
{
get
{
Hashtable ht = Session[mySessionKey] as Hashtable;
if (ht == null)
{
ht = new Hashtable();
Session[mySessionKey]=ht;
}
return ht;
}
set
{
Session[mySessionKey] = value;
}
}
我们可以用Session来保存一些页面间的变量。但是有一个不好之处就是。当用户开了两个相同页面进行操作的时候
就会造成一些冲突了。