How can we kill a user session?

Posted by Saranya Boopathi under ASP.NET on 6/11/2013 | Points: 10 | Views : 6495 | Status : [Member] | Replies : 8
How can we kill a user session in ASP.net?

Saranya Boopathi


Responses

Posted by: Satyapriyanayak on: 6/11/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Session.abandon()

If this post helps you mark it as answer
Thanks

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 6/11/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Session.abandon()

If this post helps you mark it as answer
Thanks

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 6/14/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Below are the differnt ways to remove the sessions:-

1. Session.Remove(strSessionName); -> Removes an item from the session state collection.
2. Session.RemoveAll() -> Removes all items from the session collection.
3. Session.Clear() -> Remove all items from session collection. Note: There is no difference between Clear and RemoveAll. RemoveAll() calls Clear() internally.
4. Session.Abandon() - > Cancels the current session.

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raj.Trivedi on: 6/14/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello

You can use session.abondon();

to kill the session

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arul44ece on: 6/20/2013 [Member] Starter | Points: 25

Up
0
Down
Hi saranya,

U can use
session.abandon();
Session.Clear();

Regards,

Arul R
arul44.ece@gmail.com

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rama Sagar on: 6/20/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
This works Perfect

protected void logout()
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Session.Clear();
Session.abandon();
FormsAuthentication.SignOut();
DisableBufferingOnPage()
}

protected void DisableBufferingOnPage()
{
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); // set expiry date in the
past
Response.Expires = 0;
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
}

ramasagar

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Justshekhar123 on: 6/21/2013 [Member] Starter | Points: 25

Up
0
Down
The Abandon method should write like this:
Session.Abandon();

If you want to remove a specific item from the session use (MSDN):
Session.Remove("YourItem");

If you just want to clear a value you can do:
Session["YourItem"] = null;

If you want to clear all keys do:
Session.Clear();


Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 6/26/2013 [Member] Starter | Points: 25

Up
0
Down
Inside logout button write

session.Abandon();
session.expire();

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response