Several objects in the ASP. NET kernel, core ASP. NET knowledge (6), and asp.net Kernel

Source: Internet
Author: User
Tags allkeys

Several objects in the ASP. NET kernel, core ASP. NET knowledge (6), and asp.net Kernel
Description

In fact, today's blog post is the subsequent part of the general processing program. In theory, it should be called the general processing program (2 ). However, I think the series name after the title of the article already has a number, and it is a bit strange to add another 2.

This blog post mainly introduces several objects.

1) HttpContext

2) HttpRequest

3) HttpResponse

4) context. Server

HttpContext

1.Description 

A context object of the object related to this request. It is generally used to obtain other objects.

2.

3. Description of HttpContext. Current

In the ProcessRequest method of HttpHandler, the object can be obtained through the context parameter of the method. HttpContext. Current can be used elsewhere to obtain the HttpContext object in the Current request stack, but it is recommended to pass the parameter. This is clear.

(*) HttpContext. Current cannot be obtained in the subthread.

HttpRequest

1. Description

Context. Request ["username"]; in this way, you can obtain an HttpRequest object.

The HttpRequest object describes the request information,

We can use this object to obtain the request data we want.

2. 

Visual Studio shows that an HttpRequest object can be obtained through context. Request.

3. Several methods for obtaining request data

1) context. Request. Form ["username"] get the value in the Post Request,

2) context. Request. QueryString ["username"] Get the value in the Get Request.

(PS: "xxx? Name = xx & age = 8 "is called the QueryString request parameter)

3) context. Request ["username "]

The sequence is found in QueryString, Form, Cookies, and ServerVariables. The first one is (decompilation verification)

Although the efficiency of obtaining Request data using the Request [] method is slightly reduced (almost negligible), it is really convenient to use it.

I recommend using this!

4.Types of request data 

Request Parameters obtain String data because Http is text.

Therefore, most requests require data conversion.

5. Get some request information through the HttpRequest object

1) Browser

Context. Request. Browser. Browser

2) Operating System Information

Context. Request. Browser. Platform

3) browser kernel version

Context. Request. Browser. Version

 

4) Request Message Header

// Request. Headers Request Message Header

For (int I = 0; I <context. Request. Headers. AllKeys. Length; I ++)

{

String key = context. Request. Headers. AllKeys [I];

String value = context. Request. Headers [key];

Context. Response. Write (key + "=" + value + "\ n ");

}

 

5) GET Request Method (GET or POST ?)

Context. Request. HttpMethod

6) obtain the file path of the Request page (relative)

Context. Request. Path

7) GET Request Parameters

Context. Request. QueryString

8) physical path of the requested file on the server

Context. Request. PhysicalPath

9) obtain the user proxy

Context. Request. UserAgent

10) IP address of the client

Context. Request. UserHostAddress

11) obtain the url of the client's last request

Context. Request. UrlReferrer

12) languages supported by browsers

Context. Request. userages)

PS: Right. These requests are described in detail in the http protocol!

All information obtained by HttpRequest comes from the http request message.

HttpResponse

1.Introduction 

HttpResponse is an object for setting response packets.

Use context. Response to obtain the HttpResponse object.

2. 

Visual Studio can observe that context. Response will get an HttpResponse object.

3. Redirection 

Redirect () redirection;

Redirect sends a 302 redirection to the browser, notifying the browser that "please visit the url again ", this process has gone through the process of notifying the browser "please visit the url again" and the browser to access the new url through commands.

Use the packet tool to view the Http packets in the entire response process. Because Redirect is used by the browser to re-access the new URL, you can see the changes in the URL in the address bar.

4. End ()

End () sends all the current buffered output to the client to stop this page. By performing try on End (), it is found that an exception is thrown. Therefore, the code after End () will not be executed.

Context. Server

1. Description 

Server is an HttpServerUtility type object, not a class name

2.MapPath 

MapPath ("~ /A.htm ") convert the virtual path (~ To the absolute path on the disk.

3. HtmlEncode and HtmlDecode 

HtmlEncode and HtmlDecode: HTML encoding and decoding. Encode is used to escape and display special characters

4. UrlEncode and UrlDecode 

UrlEncode and UrlDecode: url encoding and decoding. Encode Chinese characters, special characters (spaces, angle brackets), etc. when passed through URLs

 

 


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.