Request and Response objects of ASP. NET, requestresponse

Source: Internet
Author: User

Request and Response objects of ASP. NET, requestresponse

After learning the niujia news publishing system and html, I have some understanding of the B/S development process. Although I used a lot of knowledge above, I can only tell you how to create a web page. When I learned the explanation in the asp.net video, I can start to know why.

Today, we will talk about the Request and Response objects used for communication between the client and the server.

Request:When a user sends a request to a Web application using a Web browser, the client information is sent to the server. The server receives an HTTP request that contains all query string parameters or form parameters, Cookie data, and browser information. When running asp.net, encapsulate the request information into a Requset object.

Response: Encapsulates the response of the Web server to the client request, which is used to operate the HTTP information and return the result to the requester.

Both Request and Response have many attributes and methods. In the initial recognition stage, only the Redirect and Write methods of the Response object are used, and the Form and QueryString sets of the Request object are used.

The following is an example of a simple user logon interface:

The user enters the user name and password information and jumps to the Home Page. the user name and password entered are displayed on the home page.

1. Create a login. aspx file in the source view editing area:

<Span style = "font-family: KaiTi_GB2312;"> User name: <asp: TextBox ID = "txtUserName" runat = "server"> </asp: textBox> <br/> password: <asp: TextBox ID = "txtPwd" runat = "server"> </asp: TextBox> <br/> <asp: button ID = "Button1" runat = "server" Text = "login" onclick = "button#click"/> </span>
2. Write in login. aspx. cs:

<Span style = "font-family: KaiTi_GB2312;"> protected void button#click (object sender, EventArgs e) {Response. Redirect ("Main. aspx? Username = "+ txtUserName. Text +" & password = "+ txtPwd. Text); // indicates that the GET request is implicitly submitted. Therefore, Requset. QueryString must be used later. </span>
3. Create Main. aspx:

<Span style = "font-family: KaiTi_GB2312;"> protected void Page_Load (object sender, EventArgs e) {Response. write ("username:" + Request. queryString ["username"] + "<br>"); // use the QueryString attribute of the Request to obtain the user name Response passed in the URL. write ("Password:" + Request. queryString ["password"] + "<br>") ;}</span>

Redirect redirects the client to a new URL.
Write is used to output information to the client. It can output character arrays, strings, objects, or a character.

Relationship between Request and Response:

There are still many attributes and methods for Request and Reponse to continue learning and exploring.


What are the functions of the request object and response object in C?

Request: enables ASP. NET to read the HTTP value sent by the client during the Web request. For more information, see the System. Web. HttpRequest class in msdn.

Response: When a Web application is running, ASP. NET maintains information about the current application, each user session, the current HTTP request, and the requested page. For more information, see the System. Web. HttpResponse class in msdn.

These are all pasted in msdn. As long as you practice or actual project development, You can roughly summarize the usage of these two attributes.

Aspnet for receiving values transmitted using Response and Request

No, you should.
String id;
If (! String. IsNullOrEmpty (Request. QueryString ["id"])
{
Id = Request. QueryString ["id"];
}
Else
{
Id = "0 ";
}

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.