Cookie and session (session process and set out session)

Source: Internet
Author: User
Tags set cookie

The difference between a cookie and a session

A cookie is a mechanism that is stored on the client and the session is a mechanism that is stored on the server

Understanding of Cookies:

To make a simple analogy, a person is sick to go to a hospital, when the doctor gave the Patient a medical record (equivalent to a cookie) then the next time the patient went to review the case to take the cases of the team a hospital, if take this medical record to B Hospital B hospital must not admit ( Not be able to take cookies across domains, such as a.com cookies can only be read by a.com, x.a.com, y.a.com and other sites, B.Com not)

There are two types of cookies: The first is a session cookie and the second is a persistent cookie.

Session Cookie: If the expiration time is not set then the lifetime of the cookie is the current browser's session time when the browser is closed, the cookie will expire. A cookie called a session cookie for the lifetime of the browsing session

The persistent Cookie:cookie object is added with the expries attribute and the cookie is stored on the client's hard disk. Once the cookie expires, the cookie will be brought back again when you visit the site again.

Setting Persistent cookies

HttpCookie Cookie=new HttpCookie (string,string);    cookies. Expires = DateTime.Now.AddDays (3);   context.response.cookies.Add (cookie);

Remove the value of the set cookie

Judge Context.request.cookies[string]!=null first .string str=context.request.cookies[string]. Value;

Understanding of the session

1.0 session is stored in the session pool of the current server and can store any custom objects

2.0 when the browser is first accessed, it creates a session object in the session pool and generates a SessionID to be sent to the browser browser in Set-cookie to save it in the current process.

3.0 when the browser accesses any page under this website again, it will take SessionID back to the server to assign values between the 9th and 10th events in the pipeline event.

Determines whether the current page has an implementation irequiressessionstate interface removed from Set-cookie SessionID The session object is found from the server's session pool session The object is assigned to the context's session property 4.0 given the limited capacity of the session pool of the server when the stored Sessionde data is too large to cause the session pool to restart and the old data inside the session pool will be lost considering the in-process s Ession problem can use out-of-process session to solve the out-of-process session state server (advantage: fast: Unstable disadvantage) number Database (Advantages: can store a large number of data disadvantages: access to the DB for each session to compare consumption resources) settings for out-of-process sessions use the out-of-process session because the general storage shession is using data that is stored in the in-process session for limited use in Requirements for out-of-process session1.0The Prime Minister serializes the class of drugs to which the object is stored in the session [Serializable] 2.0Opening services in Computer Management-services-ASP.3.0Add a configuration to the Web. config in the current site<system.web><sessionstate stateconnectionstring= "tcpip=127.0.0.1:42424" mode= "StateServer" ></sessionState> </system.web> After the configuration is complete, you can use the out-of-process session. the advantages and disadvantages of the out-of-process session: Just take a small amount of session data ----------------------------------------------------------------------------------------------------------- --------------------------------Database advantages of out-of-process session: more stable to determine every access to the session to access the database compare consumption performance use the database Step 1.0 to findAspnet_regsql.dllWhere the assembly is located (C:\Windows\Microsoft.NET\Framework\v4.0.303192.0 Use the cmd command to switch to the current folder (CD C:\Windows\Microsoft.NET\Framework\v4.0.30319) 3.0 Enter the cmd command aspnet_regsql-s to create the database. -U sa-p 123-ssadd-sstype c-d aspnetdbIF-s behind Street 127.0.0.1 cannot connect to SQL ServerHere you can change the 127.0.0.1 to point at try-u-p-D depending on the situation
 after the configuration is complete, there will be two tables in the database and there is a trigger and a stored procedure 4.0  Using the <sessionState</sessionState> node configuration in Web. config<sessionstate sqlconnectionstring= "server=.; database=aspnetdb;uid=sa;pwd=123; "allowcustomsqldatabase=" true "mode=" SQL Server ></sessionState>The server in the node chooses the database address that you want to link database: The name of the server to which you want to link the login name of the uid:database. PWD: Login password mode database type

Cookie and session (session process and set out session)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.