Close User Session

  • Thread starter Thread starter Laurahn
  • Start date Start date
L

Laurahn

How can i configure my application for closing the session ? How can i use
the session end for closing the session ?
 
Session end is only the event fired when a session is ended. To end the
user's session you would use Session.Abandon() I believe. It will
automatically close the session after 20 minutes of inactivity anyways, and
unload the application itself after the last session is closed.
 
How can i configure my application for closing the session ? How can i use
the session end for closing the session ?

Configure a timeout or call Session.Abandon()
 
Thanks Mark.

But, i want to know what code I have to put into my app for that hapends.

Can i use a button?

i've read about put some code on Global.asax
 
But, i want to know what code I have to put into my app for that hapends.

Can i use a button?

i've read about put some code on Global.asax

In Global.asax, you have an event called Session_End - this is the event
which fires (so long as your Session is InProc) when the Session ends.

Under normal circumstances, the Session ends for two reasons:

1) it has timed out automatically, by default after 20 minutes of
inactivity, though this figure can be changed

2) it has been ended explicitly ("torn down", to use the jargon)

You may be familiar with logging out of your on-line banking application by
clicking a "Logout" button or whatever - it is the code behind such a button
where you would place the Session.Abandon() code.
 
Make a button on your web page. Give it text of "Log out". In its
server-side click event handler, simply write: Session.Abandon()

And/Or in your Web.Config file, find the section that is already there about
the session timeout and change the time from 20 minutes to something else.
 
You response doesn't really address the question. The Session_End event
handler is of no use when you are trying to end the session, only after (or
as) the session has ended.

I have been working with sessions for many, many years and you are the first
person to use the "torn down" jargon you speak of that I've ever heard.
It's not a good idea to introduce jargon that is not widely used.
 
I don't believe the application is unloaded after the last session is
unloaded. I belive the application sits idle until it crashes or is taken
off-line, but I don't believe it just ends itself.
 
Make a button on your web page. Give it text of "Log out". In its
server-side click event handler, simply write: Session.Abandon()

Wish I'd thought of that... ;-)
 
Hi Laurahn,

Regarding on the "close user session", I'd like to confirm the exact goal
you want to achieve. Generally, for ASP.NET session state you have the
following options to configure or manage it at design-time or runtime:

1. turn on or turn off it in web.config <sessionState> element.

#<sessionState> Element
http://msdn2.microsoft.com/en-us/library/h6bb9cz9(VS.71).aspx

2. You can also set "timeout" value in the above element which control the
timespan after which the runtime will dispose a certain idle sessionstate

3. You can control whether a certain ASPX page can access sessionstate
through the "@Page" directive's "EnableSessionState" attribute:

#@ Page
http://msdn2.microsoft.com/en-us/library/ydy4x04a(VS.71).aspx

4. As other members have mentioned, at runtime, in code, you can explicitly
call "Session.Abandon" method in page to terminate the current session:

#HttpSessionState.Abandon Method
http://msdn2.microsoft.com/en-au/library/system.web.sessionstate.httpsession
state.abandon.aspx

If you wonder when to call it, I think it depend on your application's code
logic, you can put the call into a page event where you want to end a
session and clear all the data in it. If you only want to remove data, but
do not want to terminate the session(and start a new one), you can simply
use the "Session.RemoveAll" or "Session.Clear" to empty the sessionstate
collectiono.

In addition, here is a popular ASP.NET session FAQ article which mentioned
many common tips about using sessionstate:


#Understanding session state modes + FAQ
http://forums.asp.net/7504/ShowPost.aspx

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
To Empty Session state there are so many ways depends on requirements:
i am taking some cases:

1. Suppose u want to End the Particular Session state

Session["KEY"] = null;
Session["abc"] = null;
OR
Session["abc"] = "";

2. Suppose u want to End all the Session's in application

Session.Abandon();
OR
Session.Clear();

So here u go.......


Nitin Sharma NXS
 
To Empty Session state there are so many ways depends on requirements:
i am taking some cases:

1. Suppose u want to End the Particular Session state

Session["KEY"] = null;
Session["abc"] = null;
OR
Session["abc"] = "";

2. Suppose u want to End all the Session's in application

Session.Abandon();
OR
Session.Clear();

So here u go.......


Nitin Sharma NXS
 
Back
Top