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 the last to give the browser what, otherwise the server pressure will be too large, the browser needs to remember these values, the next time to submit the server (please add ten on my width ), it is necessary to submit the last value to the server, let him think up. If 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, the next time the page sends the request to the server with these state information, so that the server can be based on these state information to restore the last state, similar to the medical records of the Doctor.

1, try not to do so, client-side things let the client to do.

2 . The disadvantage of saving state information in hidden fields: increase the traffic of the website, reduce the speed of access, and put the confidential data into the form there will be security issues such as data spoofing. Story: Self-print passbook, because the balance is not written to the passbook in this hidden field, the only association is the card number. To place confidential data on the server, and to distinguish between different visitors ' private areas, a unique identity is necessary.

PassURLPass

The best way to pass data between two pages is to pass through a Url , the least troublesome, and the simplest.

Pros: Simple, straightforward, clearly know who to send, data will not be messy.

Disadvantage: If multiple pages or not sure to pass between pages so that you need to go with each jump, multiple pages or not sure to pass between pages so that you need to jump every time, not confidential.

Cookies

If you want to be free to pass and read, use cookies. Cookies are site-related and are mandatory for each request to the server, in addition to sending form parameters, and all cookies related to the site are submitted to the server .

Cookiesis also stored on the browser side, and the browser will alwaysThis site is related toCookiessubmitted to the server, and the service side returns theCookiesupdate back to the database,The information can therefore be saved inCookiesand then read and modify it on the server side. The server returns data in addition toNormal.HTMLdata, it also returns the modifiedCookies, the browser gets theCookiesValue Update localCookiesViewer'sCookieswe can. Reading paperIn server-side controlCookiescases to realize the ability to remember user names

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

? Page reading value:username= request.cookies["username"]. Value; If 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.

Cookies: Can be erased, cannot be stored in a cookie that cannot be lost ;Cookie size is limited, usually a few K , hundreds of K.

Sessionprinciple

A "server-side Cookie" is required:

1. The doctor needs a private ledger to record the correspondence between the patient's number and identity;

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

His number guesses before and after the person's number, then needs a "hard to guess" Cookieconfidential data cannot be stored. If you want to store the data, you can 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 to use the above exampleASPSessionrewritten. Normal.HttpHandlerto be able to manipulateSession, to achieveIRequiresSessionStateinterface. Cookiesis present on the client,Sessionis present on the server side, the purpose is the same: Saves data related to the current client (any page of the current site can be takenSession,Cookies). Session(session) has an automatic destruction mechanism, if a period of time the browser does notAny interaction with the server, theSessionwill be destroyed at regular intervals. This is alsoWhat does not work for a period of time, the system will automatically exit.

Session Implementation Login.

Application(*)

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

After the completion of the UnLock.

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

Application_Start executes when the page is accessed .

Cite the example of a lot of books, "Statistics of visitors", each time the server on a l -lifted by a lot of books, the example of "count the number of visitors", each server on the previous

When the content is accessed, application_beginrequest will execute the quantity + +

。 Why is this bad? Large concurrent access will be very card!

Do website 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 : Protect client, not confidential

? Session : Protect the server side, cannot enlarge the 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.