ASP built-in objects-Request, Response, Server, Application, ObjectContent (1), requestapplication

Source: Internet
Author: User

ASP built-in objects-Request, Response, Server, Application, ObjectContent (1), requestapplication

The built-in objects provided by ASP in scripts make it easier for users to collect information sent through browser requests, respond to browsers, and store user information. This simplifies the work of developers.

Common built-in objects are as follows:

  • Request object, used to access any information transmitted using HTTP requests.
  • Response object, used to control the information sent to the browser.
  • Server Object, used to access methods and properties on the Server.
  • Application object used to share Application information.
  • ObjectContent object, used to control ASP script initialization transactions.

Each built-in object has its own Property, Method, Collection, or Event ). Properties are used to describe the features of built-in objects. methods are used to execute the actions of built-in objects. A set is a container that contains specific data, and events are specific operations under certain circumstances.


Request object


Request object, used to access the information transmitted to the server by any client browser during an HTTP Request, including parameter information transmitted through url, HTML form data transmitted using the GET or POST method, Cookie, and user authentication information.

The syntax format of the Request object is as follows:

Request [. collection | property | method] (variable)

Syntax description:

  • Collection, a collection member of an object. The Request object mainly includes the following:
    • The ClientCertificate set to obtain the verification field information.
    • Cookie set to obtain Cookie data.
    • QueryString collection to obtain the parameters attached to the client URL.
    • Form set, used to obtain information entered by the client in Form. (The attribute value of form method is POST)
    • ServerVariables set to obtain the header information in the server environment variables and HTTP request information sent by the client.
  • Property, a property member of an object. The Request object includes the following attributes:
    • TotalBytes attribute to get the total number of bytes sent.
  • Method, a member of the object's method. The Request object includes the following method:
    • The BinaryRead method reads data in binary format.
  • Variable, a member variable of the object.

 

Read Cookie data

 

Cookies are some of the website's tags used to record the data that users have entered on the website. Cookie can effectively reduce the number of user input data and simplify user operations. The Cookie set allows users to read all Cookie data sent in an HTTP request. The syntax of the cookie set is as follows:

Request. Cookies [(key) |. attribute]

Parameter description:

  • Cookie: specifies the name of the Cookie.
  • Key, which specifies the name of the Cookie keyword, which is different from the Cookie with the same name.
  • Attribute: the Cookie attribute. The optional attributes are as follows:
    • Specifies the Domain in which the Cookie can be read.
    • Expires: Specifies the Cookie expiration time.
    • HasKeys: Specifies whether the Cookie contains a keyword.
    • Path to specify the Path to read the Cookie.
    • Secure: Specifies whether the Cookie is Secure.

Read Cookie

if (Request.Cookies["username"]!=null ){    string username =Request.Cookies["username"].Value ;}if (Request .Cookies ["LoginInfo"]!=null ){    string username=Request .Cookies["LoginInfo"]["username"];    string password =Request.Cookies["LoginInfo"]["password"];}

Read data transmitted by Form

 

You can submit data to the server through a form that contains elements such as text, text box, check box, radio button, button, and text area. The form submission server has two methods: GET and POST. When using the POST method to submit data, you must use the Form set to retrieve the Form data sent in the HTTP request.

Syntax format of the Form set:

Request. Form (parameter) [(index) |. attribute]

Parameter description:

  • Parameter, which specifies the name of the form to be read.
  • Index: The index of the parameter to be read.
  • Attribute, parameter attribute (Count, number of parameters ).

Add new readers as follows:

Addreader. aspx

<Formmethod = "post" name = "faddreader" class = "contact" id = "faddreader"> 

Addreader. aspx. cs

Protected voidPage_Load (object sender, EventArgs e) {if (! String. isNullOrEmpty (Request. form ["reaID"]) {Reader reader = new Reader (); reader. readerId = Request. form ["reaID"]; reader. readerName = Request. form ["reaName"]; reader. readerDepartment = Request. form ["reaDepartment"]; reader. readerMajor = Request. form ["reaMajor"]; ReaderBLL readerbll = new ReaderBLL (); bool flag = false; flag = readerbll. addReader (reader); string msg; // if (flag) {msg = "added Success! ";} Else {msg =" failed to add! ";} Response. write ("<script> javascript: alert ('" + msg. toString () + "'); location. href = 'librarymanage. aspx '; </script> ");}}

The effect is as follows:

 



Read URL-passed parameters/Page redirection

 

You can use a form to submit data to the server, or use URL parameters to submit data to the server. The QueryString set allows you to retrieve string data submitted in the URL test mode in an HTTP request or element data in a form submitted in the GET mode.

Read the parameters passed by the URL

<span style="font-size:24px;">string key =Server.UrlDecode(Request.QueryString["key"]);</span>


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.