ASP built-in objects-request, Response, Server, Application, Objectcontent (ii)

Source: Internet
Author: User
Tags urlencode

Response (Reply) object

The request object, which is used during HTTP requests to access information that is passed to the server by any client browser, including parameter information passed through the URL, HTML form data passed using the Get method or post method, cookies and user authentication information, and so on.


page redirection, and passing parameters (anti-garbled processing)

Response.Redirect ("~/modifyreader.aspx?key=" + Server.URLEncode (key));

Storage of cookies

    • Stored by the cookie collection of the response object.

<span style= "FONT-SIZE:24PX;" ><span style= "White-space:pre" ></span>response.cookies["username"]. Value= "Xu Feng Zhu";</span>


    • Through the instance store of the HttpCookie object.

<span style= "FONT-SIZE:24PX;" ><span style= "White-space:pre" ></span>httpcookiecookie = new HttpCookie ("username", "Xu Feng Zhu"); <span Style= "White-space:pre" ></span>response.cookies.add (cookie);</span>

    • Storage of multi-valued cookies.
      • <span style= "FONT-SIZE:24PX;" >response.cookies["Logininfo" ["username"] = "Xu Feng Bamboo"; response.cookies["Logininfo" ["Password"]= "123456";</span>
    • <span style= "FONT-SIZE:24PX;" >    HttpCookie cookie = new HttpCookie ("Logininfo");    Cookies. Values ["username"]= "Xu Feng Bamboo";    Cookies. values["Password"]= "123456";    RESPONSE.COOKIES.ADD (cookie); </span><span style= "font-size:18px;" > </span>

Buffered page Output

The buffer property of the Response object is used to specify whether to buffer page output. If the buffered page is output, the server will send it to the client only if all server scripts for the page have been processed, or if the flush and end methods are called.

The buffer property must be set before any output, that is, the Response.Buffer should be called in the first line of the. asp document, and the buffer property can no longer be set when the server sends the information to the client.


Server Object Syntax

Syntax format for the Server object:

Server[.property|method]

Syntax Description:

    • property, the properties of the object (the ScriptTimeout property, which specifies the script time-out period).
    • Method, Methods
      • CreateObject, create a Component object,
      • HTMLEncode, HTML-encodes a string.
      • MapPath, the relative path or virtual path is mapped to a physical path on the server.
      • urlencode, URL encoding of the string.

Session (Conversation) object

Session objects can be used to store information that is required for a particular user session. This way, when a user jumps between pages of an application, the variables stored in the session object are not lost, but they persist throughout the session.

When a user requests a Web page from an application, if the user does not yet have a session, the Web server automatically creates a Session object. When the session expires or is discarded, the server terminates the session.

We hope that the background management in the case of how long no operation, let the session expire, re-login, you can use session.timeout=5, in minutes, indicating no other actions within 5 minutes, it is invalid, or in the configuration file configuration < sessionstatetimeout= "5" mode= "InProc"/> can also.

A brief talk about the difference between several methods of the session:

Session.clear (): Indicates that the key value of all sessions in the session is emptied, but session still exists, equal to Session.removeall ()

session["Admin"]=null: The value of the key will be set to empty, and released, and session["admin"]= "" not the same, it emptied, but the session does not release, equal to the session. Remove ("name");

Session.Abandon () is to delete the current session object, the next time is the new session.


The main difference is that when Session.Abandon is used, the Session_End method is called (in InProc mode). The Session_Start method is fired when the next request arrives. And Session.clear just clears all the data in the session and does not abort the session, so the methods are not invoked, the Abandon method is used to actively end the session, and if the method is not called, the current session is automatically ended when the session times out.

Add:

Clearing cookies

A

<span style= "FONT-SIZE:24PX;" >tpcookie Cookie =system.web.httpcontext.current.request.cookies.get ("Tuser"); Expires =datetime.now.adddays (-1); SYSTEM.WEB.HTTPCONTEXT.CURRENT.RESPONSE.COOKIES.ADD (Cookie);</span>

B

<span style= "FONT-SIZE:24PX;" >tpcookie httpCookie =request.cookies["HttpCookie"];httpcookie.expires =datetime.now.adddays (-1); RESPONSE.COOKIES.ADD (HttpCookie);</span>

AB two methods are available

The difference between a Session and a cookie

    • The session exists on the server side, and the cookie is present on the client.
    • The session does not need cookies to support and is not affected by browser settings, it can record each visitor's information, Independent on the server side, than Cookie security.
    • The session is in memory, and the browser closes it "dead", the cookie exists as a file, and it can modify its "surviving" time.


Application (Application) object

Use the Application object to share data information among all users of the application and persist the data while the server is running.

Syntax format for application objects:

Application[.collection|method] (variable)

The syntax is described as follows:

    • A collection of collection, objects.
      • Contents, getting static objects in the application
      • Staticobject, gets the static object in the application.
    • Method, Object methods.
      • lock, which locks the application object.
      • Unlock, unlocks the Application object.
    • Variable, the member variable of the object.

In addition, the Application object includes two events such as Application_OnStart (application start) and Application_OnEnd (Application end), both of which must be placed in the Global.asa file.

Sharing data in an application

The Contents collection and StaticObjects collection of the Application object contains all the shared information data in the application, essentially similar to the corresponding collection of Session objects.


Securely share data

Because multiple users can share application objects, the lock method and the Unlock method are required to ensure that multiple users cannot change application objects at the same time.

The lock method is used to prevent other users from modifying objects stored in the Application object to ensure that only one user can modify and access the Application object at the same time.

The Unlock method is used to unbind an Application object that is locked by using the lock method before other users can access the objects in the Application object. If the user does not see a call to the Unlock method, the server will unlock the Application object after the ASP file finishes or times out.


Summarize

    • ASP built-in objects
    • The Request object, which includes reading the validation field information, reading the cookie data, reading the data passed from the form or URL, reading the server environment variables, and so on.
    • Response objects, including writing cookie data, buffering page output, page redirection, outputting data to a page, and more.
    • Server objects, including script time-out periods, creating component objects, HTML or URL encoding of strings, mapping to server physical paths, and so on.
    • Session object, which includes reading the data in the session, reading the session ID, deleting the Session object, and so on.
    • Application objects, including sharing data in applications, sharing data securely, and more.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ASP built-in objects-request, Response, Server, Application, Objectcontent (ii)

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.