Unlike cookies, Session status has no size limit. If there are extreme requirements, you can use Session to save G data. In addition, the Session can save more complex objects. For example, you can save a DataSet in the Session.
When a Session status is used, a cookie named ASP. NET_SessionId is automatically added to the browser. This cookie contains a unique identifier that can be used to track users during page switching.
By default, if the cookie is disabled, the Session status does not work properly. By default, if the user does not request any page for more than 20 minutes, the data stored in the Session state will be discarded.
ASP. NET Session Object
The main application programming interface used by users to operate the Session status is the HttpSessionState class. This object is exposed by Page. Session, Context. Session, UserControl. Session, WebService. Session, and Application. Session attributes. That is to say, you can access the Session status from anywhere.
HttpSessionState supports the following attributes:
CookieMode -- used to specify whether to enable cookie-independent Session status.
Count -- used to obtain the number of items in the Session state.
IsCookieless -- used to specify whether to enable the cookie-independent Session Status function.
IsNewSession -- used to check whether a new user session is created for the current request;
IsReadOnly -- read-only or not;
Keys -- used to obtain the name list of items saved in the Session state;
Mode -- specifies the storage handler in the current Session state.
SessionID -- used to obtain a unique session identifier;
Timeout -- used to specify the number of minutes for the Web server to assume that the user leaves and cancels the Session status. The maximum value is 525600 minutes and 1 year );
The HttpSessionState object also includes the following methods:
Abandon -- used to terminate a user session;
Clear -- used to Clear all items in the Session state;
Remove -- used to delete a specific project from the Session state;
ASP. NET submit session events
Global. asax contains two events that can be processed in the associated Session state: Session Start and Session End events. The Session Start event is triggered when a new Session starts, and the Session End event is triggered when the Session ends.
Session failure Control
By default, the user does not request a page within 20 minutes and the Session expires. You can modify the Session expiration time in the configuration file:
- <?xml version="1.0"?>
- <configuration>
- <system.web>
- <sessionState timeout="60" />
- </system.web>
- </configuration>
You can also change the expiration time of the Session state by programming.
Session. Timeout = 60;
Session status using Cookieless
By default, Session status depends on cookie. If the cookie is disabled in the browser, the Session status cannot work by default. In this case, you can use a non-cookie Session. When a non-cookie Session is enabled, the user's session ID will be added to the URL of the page.
You can modify the sessionState element of the configuration file and set cookieless to AutoDetect.
- <?xml version="1.0"?>
- <configuration>
- <system.web>
- <sessionState cookieless="AutoDetect"
- regenerateExpiredSessionId="true" />
- </system.web>
- </configuration>
- SQL statements in ASP. NET
- Use StringBuilder in ASP. NET
- Response. Write in ASP. NET
- Analysis on ASP. NET authorization Module
- Processing Process for ASP. NET Runtime