Kel*_*sey 61
该Abandon
方法应该工作(MSDN):
Session.Abandon();
Run Code Online (Sandbox Code Playgroud)
如果要从会话使用中删除特定项目(MSDN):
Session.Remove("YourItem");
Run Code Online (Sandbox Code Playgroud)
编辑:如果您只想清除值,您可以执行以下操作:
Session["YourItem"] = null;
Run Code Online (Sandbox Code Playgroud)
如果要清除所有键,请执行以下操作:
Session.Clear();
Run Code Online (Sandbox Code Playgroud)
如果这些都不适合你,那么就会发生一些可疑的事情.我会检查您分配值的位置,并确认在清除值后没有重新分配.
简单检查一下:
Session["YourKey"] = "Test"; // creates the key
Session.Remove("YourKey"); // removes the key
bool gone = (Session["YourKey"] == null); // tests that the remove worked
Run Code Online (Sandbox Code Playgroud)
小智 8
指示客户端浏览器清除会话ID cookie值也是一个好主意.
Session.Clear();
Session.Abandon();
Response.Cookies["ASP.NET_SessionId"].Value = string.Empty;
Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddMonths(-10);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
155301 次 |
最近记录: |