Detailed explanation of iis session_PHP tutorial

WBOY
Release: 2016-07-20 11:09:39
Original
1040 people have browsed it

Basic session operationsAdd and modify session items session.add("test", datetime.now);
session["test"] = datetime.now;Add and modify session The method is the same. When the specified session ID does not exist, the system will add it. The system will update when present. Delete the session item session.remove("test"); Do not use session["test"] = null; This just sets the value to null! Remove all session items session.clear(); or session.removeall(); Terminate the current session state session.abandon(); Number of current session items session.count Current sessionids session.sessionidWhen session was createdFor all browsers (ie, chrome, firefox), when the browser is opened for the first time (when the browser is not currently running), a new session will be created on the server side. IE browser, when an existing browser is running, opening a new browser will create a new session. In Chrome and Firefox, when an existing browser is running, opening a new browser will not create a new session. When the session expires, a session will be created when access continues. The session_start method in global.asax is triggered when the session is created. When does the session expire?

  • The code session.abandon(); causes the session to expire.
  • The session times out and expires automatically.
  • web.config has been modified and will expire.
  • Caused by the iis application pool being recycled.
The session_end method in global.asax will be triggered when the session expires. Strange question: session.abandon(); has the same effect as automatic expiration of session timeout. After the expiration, the session_start and session_end methods will be executed when the page is refreshed. How to avoid adding session["sessionstartdatetime"] = datetime.now; in session_start; after calling session.abandon(); execute response.cookies.add(new httpcookie("asp tutorial.net_sessionid", "")); let sessionid Reset. session expiration timeSet the minute value in web.config. (The default expiration is 20 minutes if not filled in) The session timeout setting of iis does not take effect. (The setting location is as shown below) The application pool associated with the website has a recycling time limit. Even after testing, it doesn't work. But it will take effect if you manually recycle or set a scheduled recycle. (How to associate the website application pool is as shown below) How to prevent session expiration You can set a longer session expiration time. However, if it is set too long, it may cause the server to be overburdened. Set the session mode to out-of-process or database tutorial. It will not be discussed here. The general actual situation may be that the editing process takes a long time when users submit certain pages, such as blog post submission pages. It may be found that the session has expired during submission. As a result, user information is lost and articles cannot be submitted. If this is the case, you may just want to extend the session time of the specified page. A blank page in the background can be accessed regularly through ajax. to keep the session online. Create an empty page updatesession.aspx. Note: Add in page_load. Note: When ajax requests an aspx page, the aspx page should be set to not allow caching! protected void page_load(object sender, eventargs e)
{
response.appendheader("pragma", "no-cache");
response.appendheader("cache-control", "no-cache, must-revalidate");
response.appendheader("expires", "0");
}About sessionidWhen the session expires, the sessionid does not change. Call response.cookies.add(new httpcookie("asp.net tutorial_sessionid", "")); to set the sessionid. When it is set to empty, the server will create a new session. The old session has not been released. When set to other existing sessionid values, the session at this time will obtain the specified session. This is session hijacking. How to count the number of sessions on the current website. Create class view sourceprint?
<table> <tbody> <tr> <td> <code><strong><font color="#006699">public</font></strong> <strong><font color="#006699">class</font></strong> constants
public
{
class constants
    <font color="#808080">/// <summary> </font>
    <font color="#808080">/// 当前session个数 </font>
    <font color="#808080">/// </summary> </font>
    <strong><font color="#006699">public</font></strong> <strong><font color="#006699">static</font></strong> <strong><font color="#006699">int</font></strong> sessioncount = 0;
  
    <font color="#808080">/// <summary> </font>
    <font color="#808080">/// 累计session个数 </font>
    <font color="#808080">/// </summary> </font>
    <strong><font color="#006699">public</font></strong> <strong><font color="#006699">static</font></strong> <strong><font color="#006699">int</font></strong> sessionallcount = 0;
}
Add view sourceprint in global.asax?
<strong><font color="#006699">void</font></strong> session_start(<strong><font color="#006699">object</font></strong> sender, eventargs e)
{
    constants.sessionallcount++;
    constants.sessioncount++;
    session[<font color="#0000ff">"sessionstartdatetime"</font>] = datetime.now;
}
  
<strong><font color="#006699">void</font></strong> session_end(<strong><font color="#006699">object</font></strong> sender, eventargs e)
{
    constants.sessioncount--;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444796.htmlTechArticleBasic operation of session Add and modify session items session.add(test, datetime.now); session[test] = datetime .now; The methods for adding and modifying sessions are the same. When the specified session identifier does not exist...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template