0

Suppose the user login by entering his or her details
When clicking on Login button, I m setting the session variable

Session["UserName"] = txtUserName.Text;

I want dat when he or she
clicks on sign out(hyperlink)..I want to expire the session, can somebody tell me how to expire the session?

Or there is if any other way to do,what i want.plz tell me!

5
Contributors
8
Replies
9
Views
8 Years
Discussion Span
Last Post by dnanetwork
0

Hi Use session.Abandon().
It will automatically closes all the sessions opened upto that function.

0

can u tell me wats the diff b/w the foll....ALL three does the same work or not!!!! When 2 use Session.Abandon();, when to use Session.Clear(); , When to use Session.RemoveAll()?


Session.Abandon();

Session.RemoveAll(); This removes all the sessions in the current Scope

Session.Clear();

0

Session.RemoveAll() and Session.Clear() are same. Both methods removes all keys and values from the session-state collection. But the current Session is not cancelled. That is Session.SessionID will be the same before and after calling these two methods.

But Session.Abandon() will cancel the current Session. That is, Once the Abandon method is called, the current session is no longer valid and a new session can be started.

Abandon causes the Session_OnEnd() event in the Global.asax to be raised. A new Session_OnStart() event will be raised on the next request.

Using these methods depends on your requirement. For example, you can call Session.Abandon() when the use logout your application.

Also you may want to clear all the keys in the Session object when the user goes to a landing page, for example, home page. In this scenario, you can use Session.Clear().

0

ramesh i'm very impressed but i had one query...

when session.abandon() is called and wot if my server don;t have

global.asax file....does it gonna work...just like u said..!

0

The Session.Abondon will cancel the session even if you don't have Global.asax file. The only thing is the Session_OnEnd() will not be executed.

0

The Session.Abondon will cancel the session even if you don't have Global.asax file. The only thing is the Session_OnEnd() will not be executed.

thxn bro..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.