ASP. NET built-in Object Request, response

Source: Internet
Author: User

Note: This article is mainly for reference to ASP. NET evening notes. I added my own documents.

Objects that can be used without the need for new during Asp.net development, such:

Request, response, server, session, Cookie, Application
All webpages in Asp.net inherit from the class system. Web. UI. Page. HTTP is a stateless protocol, that is, it does not remember who requested it last time and does not take the initiative to ask the client. The server will respond only after the client initiates a request.

1,Request object
The request encapsulates the client request information. Common Request attributes are as follows:

property name Value Type description
applicationpath string obtain the root path of the requested resource on the website
contentencoding encoding set the encoding of the request object
cookies httpcookiecollection set of cookies sent from the client to the server
querystring namevaluecollection query string set of the current request
urlreferrer URI retrieve the URL from which the user jumps to the current page

2. response object
response indicates the server response object. Each time a client sends a request, the server uses a response object to process the request. After the request is processed, the server destroys the object, in order to continue to accept other client requests.
common response attributes:

property name Value Type description
charset string indicates the character set used by the output stream
contentencoding encoding set the encoding of the output stream
contentlengt int size of the output stream in bytes
contenttype string http mime type of the output stream
output textwriter character output stream of the server response object
cookies httpcookiecollection Cookie set sent from the server to the client
redirectlocation string redirect the current request

Common response methods

Method Name Return Value Type Description
Appendcookie Void Add a cookie to the cookie set of the response object
Clear Void Clear all content output in the buffer
Close Void Close the connection from the current server to the client
End Void Terminate the response and send the output in the buffer to the client.
Redirect Void Redirect current request

Example: Create An ASPX page for a single file andCodePaste in the past)Request and response

  <% @ Page Language = " C # " Contenttype = " Text/html " Responseencoding = " Gb2312 "   %>  
  <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >  
  < Html Xmlns = "Http://www.w3.org/1999/xhtml" >  
  < Head >  
  < Meta HTTP-equiv = "Content-Type" Content = "Text/html; charset = gb2312"   />  
  < Title > Request example </ Title >  
  </ Head >  
  < Body >  
  < Table Border = "1" Width = "600px" Bordercolordark = "#2b72a2" Bordercolorlight = "#993333" >  
  < Tr > < TD Colspan = "2" Bgcolor = "#80 ffff" > Request </ TD > </ Tr >  
  < Tr > < TD > Applicationpath (website path) </ TD > < TD > <% = Request. applicationpath %> </ TD > </ Tr >  
  < Tr > < TD > Contentencoding) </ TD > < TD > <% = Request. contentencoding %> </ TD > </ Tr >  
  < Tr > < TD > Number of cookies </ TD > < TD > <% = Request. Cookies. Count %> </ TD > </ Tr >  
  < Tr > < TD > Querystring count </ TD > < TD > <% = Request. querystring. Count %> </ TD > </ Tr >  
  < Tr > < TD > Urlreferrer (previous request page) </ TD > < TD >   <% = Request. urlreferrer %> </ TD > </ Tr >

< Tr > < TD Colspan = "2" Bgcolor = "#80 ffff" > Response </ TD > </ Tr >  
  < Tr > < TD > Charset </ TD > < TD > <% = Response. charset %> </ TD > </ Tr >  
  < Tr > < TD > Contentencoding) </ TD > < TD > <% = Response. contentencoding %> </ TD > </ Tr >  
  < Tr > < TD > Number of cookies </ TD > < TD > <% = Response. Cookies. Count %> </ TD > </ Tr >  
  < Tr > < TD > Contenttype </ TD > < TD > <% = Response. contenttype %> </ TD > </ Tr >  
  </ Table >  
  </ Body >  
  </ Html >

Effect

From the figure we can see that: using Dreamweaver to create a web page, if the default encoding, the request object character encoding is UTF-8, and the response object encoding is gb2312. This is very likely to cause garbled characters.
In addition, it should be noted that the common Server Response contenttype is "text/html", which indicates that the response is transmitted in the form of HTML files. There are also some other forms of contenttype, as shown below:
Image/JPEG: The response object is a JPEG image.
Text/xml: The response object is an XML file.
Text/JavaScript: The response object is a Javascript script file.
The default contenttype attribute of response is "text/html", indicating that the server responds to client requests in HTML files. If you need to respond to client requests in other ways, you need to set the contenttype attribute. If we need to respond to the client request in JPEG format, we need to set the contenttype attribute to "image/JPEG" and then output the image content to the client, in this way, the client will see JPEG images instead of HTML files.

Related Article

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.