Ending a sessionI've shown how a new session starts, but how does it end? There are two ways:1. The user doesn't request or refresh a page within a specific time period. 2. Session.Abandon( ) is called from your ASP page. Sessions timing outBy default, if a user doesn't make any requests from the server for 20 minutes that session is ended. Similar to before, the Session_OnEnd( ) function in global.asa is called at that point. Note that you can only use the Application, Session and Server objects in that function.Setting timeout for the entire applicationYou can change the timeout value for all your pages by configuring IIS. On earlier versions of IIS on Windows NT you changed this setting in the Internet Service Manager, but that was renamed to the "Internet Information Services snap-in" in Windows 2000. To find the IIS snap-in go to Control Panel / Administrative Tools / Internet Services Manager and then view the properties for the Default Web Site. On that dialog go to the Home Directory tab, and choose the Configuration button (nearly there!). Choose the App Options tab, and <phew> there's the setting! Set it to as small a number as possible to increase the efficiency of your server. Set it larger than the time you expect users to read your largest page, or they could lose their session! Setting timeout for a single sessionYou can also override the timeout for a single session by adding the following line into your code (although I can't think why you'd want to do this):// this session will timeout after 5 minutes inactivity
Session.Timeout = 5;
|
Abandoning a sessionYou can end a session (almost) immediately by calling Session.Abandon( ). The rest of the page is still executed, and the Session object is still available for that page, but the session is ended when the page finishes executing. If you want the page to stop processing immediately too, call Response.End( ).Remember that even though the session has ended, if the user requests a new page from your site a new session will automatically start. |