当我从页面退出时如何杀死会话... [英] How To Kill The Session When I Logout From The Page...
本文介绍了当我从页面退出时如何杀死会话...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用我的凭据登录后,我复制了URl,现在我从那里注销并通过复制URL到达我的登录页面。如何解决它。
登录
string username = txtusr.Value;
Session [user] = list.Count();
if(list.Count == 0)
{
Response.Redirect(Home.aspx);
}
其他
{
Response.Redirect(details.aspx?username =+ username);注销我使用
<
$ b leadattribute> pre lang = cs > Session.Contents.RemoveAll();
Session.Abandon();
Session.Remove(& quot; user& quot;); < / pre >
解决方案
Abandon方法应该有效(MSDN):< br $>
Session.Abandon();
如果你想删除一个会话使用中的特定项目(MSDN):
Session.Remove( YourItem);
编辑:如果您只想清除值,您可以执行以下操作:
会话[ YourItem] = null ;
如果要清除所有键,请执行以下操作:< br $>
Session.Clear();
Quote://如果使用表单身份验证
< blockquote class = quote>< div class = op> Quote:< / div > HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();
HttpContext.Current.User = null ;
System.Web.Security.FormsAuthentication.SignOut(); < / blockquote > 跨度>
when i login with my credentials after that i copy the URl and now i logout from that and past the copy URL here it goes to my login page.How to resolve it.
In Login
string username = txtusr.Value;
Session["user"] = list.Count(); if (list.Count == 0) { Response.Redirect("Home.aspx"); } else { Response.Redirect("details.aspx?username=" + username); } when logout i'm using <pre lang="cs">Session.Contents.RemoveAll(); Session.Abandon(); Session.Remove("user");</pre>解决方案The Abandon method should work (MSDN):
Session.Abandon();
If you want to remove a specific item from the session use (MSDN):
Session.Remove("YourItem");
EDIT: If you just want to clear a value you can do:
Session["YourItem"] = null;
If you want to clear all keys do:
Session.Clear();
Quote:// if forms auth is used
<blockquote class="quote"><div class="op">Quote:</div>HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Abandon(); HttpContext.Current.User = null; System.Web.Security.FormsAuthentication.SignOut();</blockquote>
这篇关于当我从页面退出时如何杀死会话...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文