
如何彻底清除Session["UserName"] ?
ASP.NET(C#)和Web设计的时候,出现这样一个问题:登录的时候,保存Session["UserName"]=“小明”,然后进入一个管理页面,该管理页面显示出登录者...
ASP.NET(C#)和Web设计的时候,出现这样一个问题: 登录的时候,保存Session["UserName"] =“小明”,然后进入一个管理页面,该管理页面显示出登录者是 "小明",现在把这个网址复制下来。。。然后注销,即Session["UserName"] =null 再重新登录,Session["UserName"] =“二狗”,然后把刚才复制下来的网址粘贴上去访问,发现显示的登录者依然是“小明”,明明注销了,为什么显示的登录者还是 “小明”,而不是“二狗”呢?请问这种使用Session["UserName"] 保存登录者的方法,如何才能彻底清除Session["UserName"] ???
展开
2013-05-23
展开全部
你可以使用如下代码清除:protected void Button1_Click(object sender, EventArgs e)
if Session("UserName") != null
Session.Remove("UserName");
Session.RemoveAll(); Response.Cookies("UserName").Expires = DateTime.Now;
9 Page.RegisterStartupScript("","<script>window.top.document.location.href='index.aspx';</script>");
if Session("UserName") != null
Session.Remove("UserName");
Session.RemoveAll(); Response.Cookies("UserName").Expires = DateTime.Now;
9 Page.RegisterStartupScript("","<script>window.top.document.location.href='index.aspx';</script>");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-05-23
展开全部
Session.Clear();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询