Delivery and saving of ASP.

Source: Internet
Author: User

HTTP Stateless httpprotocol is stateless and will not remember the last time and the page "What Happened" (the story of the firstLove -Times ").

Test:Private field + +. Server does not remember what was given to the browser last time. Otherwise the server pressure will be too big, the browser needs to remember these values, the next time you submit the server (please add ten on my width ), it is necessary to submit the last value to the server, let him recall. Suppose you want to know the last state, one method is to save the state information to the page table consignments (Implementation) before the end of the browser response, and the next time the page makes a request to the server with these state information, so that the server can restore the last state based on these state information, Similar to the medical records of the Doctor.

1, try not to do so, the client thing let the client to do.

2 . The disadvantage of saving state information in hidden fields: increase the traffic on the site, reduce the speed of access, confidential data into the form there will be data spoofing and other security issues. Story: Self-printing passbook, because the remaining amount is not written to the passbook in this hidden field, the only association is the card number.

To put confidential data on the server. and different access to the private areas of the visitors, then need a unique identity.

PassURLPass

The best way to pass data between two pages, perhaps the least cumbersome, is to pass through a Url .

Strengths: Simple, direct. Know who to send, the data will not be messy.

Cons: If you have multiple pages or are not sure to pass between pages then you need to take each jump. Multiple pages or not sure to pass between pages so that you need to jump every time with, not confidential.

Cookies

Suppose you want to be free to pass and read, with a Cookie.

Cookies is related to the site, and each time the request to the server , in addition to sending form parameters, will also be related to the site all cookies are submitted to the server, is mandatory.

Cookies is also stored on the browser side, and the browser submits the cookie associated with the site to the server on each request, and the cookie returned by the service Updated back to the database so that information can be saved in a Cookie and then read and altered on the server side.

The server returns data, in addition to normal HTML data, and returns the cookie that was changed, and the browser updates the valueof the cookie to the local cookies are available on the cookie browser . read the paper on the server side control Cookie case, realize the function of remembering username

? Set the value of the page:Response.setcookie (New HttpCookie ("UserName",UserName));

? Page reading value:username= request.cookies["username"]. Value; Assuming that the Expires is not set, then the life cycle is closed and the browser terminates, otherwise "up" to Expires .

Disadvantages of Cookies:

You cannot store too much information, and confidential information cannot be saved.

Cookies are not available across different browsers.

Cookie: is capable of being erased. You cannot store data that cannot be lost in a cookie ;Cookie size is limited, usually just a few K, hundreds of K.

Sessionprinciple

A "server-side Cookie" is required:

1, the doctor needs a private ledger, records the patient number and the corresponding relationship of identity;

2, in order to prevent the patient according to the distribution

His number is the number of people before and after the test, so a "very difficult to predict" Cookie is required to store confidential data.

Suppose you want to store the data to save aGuidto theCookiesIn the server, and then create aGuidto beKey, complex data isValueGlobalDictionary. Put inApplicationthe. This isValueGlobalDictionary. Put inApplicationthe. ThisGuidis the equivalent of a user's "token"

aspalready built-in.Sessionmechanism. Use the examples aboveASPSessionrewritten. Normal.HttpHandlerto be able to manipulateSession, to achieveIRequiresSessionStateinterface. Cookiesis the presence of the client. Sessionis present on the server side, the purpose is the same: Saves data related to the current client (whichever page of the current site is availableSession,Cookies). Session(session) has its own initiative to destroy the mechanism, assuming a period of time the browser does notInteracting with the server regardless of what happens, theSessionwill be destroyed at regular intervals. This is alsoWhat does not operate for a period of time, the system will voluntarily exit.

Session Implementation Login.

Application(*)

Application is the application of global objects. be shared by all. Before Operation , Lock,

After the completion of the UnLock.

Add a "Global Application class" Global.asaxwhen the application first

Application_Start Run when the page is interviewed .

The example "statistic visitor number", which was broken by a lot of books, each time the server had a sample "statistic number of visitors" that was broken by a lot of books, each time the server

When the content is interviewed, Application_BeginRequest will run the quantity + +

。 Why is this bad? Big concurrent interview will be very card!

Do site development try not to use application, also very few need to use it.

Summarize

Differences and different uses of several data transfers

? Application : Global data, do not use

? URL : precise transmission, trouble with use.

? Hidden fields: Not confidential

? Cookies : Save in client, not confidential

? Session : Save on server side, cannot enlarge data

Delivery and saving of ASP.

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.