[C#/ASP.NET] Global.asax 파일이 없다 & Session Timeout 설정

1. Global.asax 파일이 없다
Project> Add New Item > Global Application Class > Add
===================================
2. Session Timeout 설정
(http://jus ··· uts.html로 부터 퍼옴)

SessionState Timeout
This is the number of minutes before an ASP.NET user session is terminated. It must be an integer, and it is in minutes. The default is to terminate the session after 20 minutes and the application will throw an exception when accessing an terminated session. Another way to think of this is that it is the time between requests for a given session (which is per user) before a session is terminated.

I recommend reading Idle Timeout section below to see how these are related.


Using Web.config
<system.web>
<sessionState timeout="20" />
<system.web>


Using IIS
You can get to the setting by: Open IIS | Properties on Web Site | ASP.NET tab | Edit Configuration... (or Edit Global Configuration to change for more than one site) | State Management tab.

Here you will see a textfield with a label that says "Session timeout (minutes) with a default value of 20 minutes.

Session Timeout Event
When the session times out it fires an event called: Session_End and then when the user hits the page again (after it has expired or the first time), it will start a new session and the Session_Start event is called. It is important to know that the only thing you can really do in the Session_End event is do clean up. This is because this event fire even if a user doesn't hit a page again. In other words, if a session times out due to inactivity, the Session_End is fired even if the user never refreshes the page, etc. It is independent of the page lifecycle. These events are defined in the Global.asax file.


Detecting when a session has timed out
The short answer to this is that you have a session time when the following conditions are met:
Context.Session != null
AND Context.Session.IsNewSession == true
AND Page.Request.Headers["Cookie"] != null
AND Page.Request.Header["Cookie"].indexOf("ASP.NET_SessionId") >= 0

The long answer is read this blog for more details and sample code: http://www ··· 1228.asp
and http://aspalliance.com/520
2009/04/28 13:43 2009/04/28 13:43
JUNN
Programming 2009/04/28 13:43

트랙백 주소 : http://www.junn.net/tt/trackback/309

댓글을 달아 주세요

[로그인][오픈아이디란?]

Powerd by Textcube,designed by criuce, Revised by JUNN