Home Backend Development C#.Net Tutorial Let's talk about the use of the two objects Request and Response

Let's talk about the use of the two objects Request and Response

May 26, 2018 am 10:32 AM


ASP.NET objects include the following:

This article starts from "## In #asp.net, we will talk about the use of the two objects Request and Response using the example of submitting to the background through the form submit in #asp.net.

(1) Introduction of examples

#                                                                                                 The form code in body>:

<body>
    <form method="get" action="WebForm1.aspx">
        <table style="width:50%;">
            <tr>
                <td> </td>
                <td>
                    <input id="text1"  name="txtUserName" type="text" /></td>
                <td class="auto-style1"> </td>
            </tr>
            <tr>
                <td> </td>
                <td>
                    <input id="text2"  name="txtUserPwd" type="text" /></td>
                <td class="auto-style1"> </td>
            </tr>
            <tr>
                <td> </td>
                <td>
                    <input id="ccc" type="submit" value="提交" /></td>
                <td class="auto-style1"> </td>
            </tr>
        </table>
    </form>
</body>
Copy after login
The method

method in the form is the form submission method.


The
action

method in the form specifies the submission target of the form.

Action="WebFrom1" refers to the form that points to the WebForm1 form after submission. In the page of this path, you can use Request.From to receive the data of the Post

method. Use Requet.QuestString to accept data from

Get. Whether to use Post or Get can be set in the Method attribute in the form. ##                                                                                                  Backend C# code:

    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Request三种获取表单值得方法。

            #region  对于post方法递交表单的获取值方法
            //string userName = Request.Form.Get("txtUserName").ToString();
            //string userPwd = Request.Form.Get("txtUserPwd").ToString();
            #endregion

            #region  对于get方法递交表单的获取值方法
            //string userName = Request.QueryString["txtUserName"].ToString();  
            //string userPwd = Request.QueryString["txtUserPwd"].ToString();
            #endregion
           
            #region  对两者方法都适用的方法,运用Reuqest的索引值去获取所要求的表单值
            string userName = Request["txtUserName"].ToString();
            string userPwd = Request["txtUserPwd"].ToString();
            #endregion
            Response.Write("登陆的用户名为:" + userName + ";密码为:" + userPwd);

            if (userName=="a"&&userPwd=="b")
            {
                Response.Redirect("WebForm2.aspx");
            }
            else
            {
                Response.Redirect("login.html");
            }       
        }
    }
Copy after login

(2) Request object and Response object Usage summary

1. Request object

## Request three methods to obtain form values The specific implementation has been written into the examples of future generations of code, so I will not go into details here. What needs to be noted here is:

The difference between get and post methods is as follows:

The get method is submitted, and a value can be passed by directly defining a url. The disadvantage is that the passed value is clearly displayed. Because the characters displayed by the browser have a length, the display of its data is limited. Post submission means submitting the data as a whole collection. The parameters passed by the value-passing method of the post method will not be displayed in clear code in the URL.

2. Response object

## The response object, the most important method used is response.write(string ) and response.redirect(url).

The function of response.write(string) is to return data (write data) from the server to the client.

The function of response.rediec("url") is to redirect another web page on the server side.

[Related recommendations]

1.

Summary of the usage examples of the Request object of Asp.net built-in objects

2. Share a small case of Request object3.

Share request in asp Object five methods to obtain client data4.

Detailed explanation of ASP.NET system object Request

The above is the detailed content of Let's talk about the use of the two objects Request and Response. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
What does php request mean? What does php request mean? Jul 07, 2021 pm 01:49 PM

The Chinese meaning of request is "request". It is a global variable in PHP and is an array containing "$_POST", "$_GET" and "$_COOKIE". The "$_REQUEST" variable can obtain data and COOKIE information submitted by POST or GET.

Laravel Development: How to return a response using Laravel Response? Laravel Development: How to return a response using Laravel Response? Jun 14, 2023 am 10:39 AM

Laravel is a popular PHP web development framework that provides many useful features and components, including response return. Response return is a very important concept in Laravel as it controls how the web application provides information to the client. In this article, we will detail the various ways Laravel responses are returned and how to use LaravelResponse to return responses. To return a string in Laravel, you can use the Response object

How to use the urllib.request.urlopen() function to send a GET request in Python 3.x How to use the urllib.request.urlopen() function to send a GET request in Python 3.x Jul 30, 2023 am 11:28 AM

How to use the urllib.request.urlopen() function in Python3.x to send a GET request. In network programming, we often need to obtain data from a remote server by sending an HTTP request. In Python, we can use the urllib.request.urlopen() function in the urllib module to send an HTTP request and get the response returned by the server. This article will introduce how to use

How to encapsulate Vue3 Axios interceptor into request file How to encapsulate Vue3 Axios interceptor into request file May 19, 2023 am 11:49 AM

1. Create a new file called request.js and import Axios: importaxiosfrom'axios'; 2. Create a function called request and export it: This will create a function called request and export it Set up a new Axios instance with a base URL. To add timeout settings in a wrapped Axios instance, you can pass the timeout option when creating the Axios instance. exportconstrequest=axios.create({baseURL:'https://example.

What is request in PHP What is request in PHP Jun 01, 2023 am 10:12 AM

Request in PHP refers to request. It is a super global variable in PHP. It is used to collect data submitted by HTML forms and parameters in URLs. It can obtain data from GET and POST requests at the same time. Note that $_request is an associative array. , where the keys are the names of the form fields and the values ​​are the values ​​of the form fields. When using the $_request variable, user-entered data should always be validated and filtered to avoid security issues.

What is the Request object in PHP? What is the Request object in PHP? Feb 27, 2024 pm 09:06 PM

The Request object in PHP is an object used to handle HTTP requests sent by the client to the server. Through the Request object, we can obtain the client's request information, such as request method, request header information, request parameters, etc., so as to process and respond to the request. In PHP, you can use global variables such as $_REQUEST, $_GET, $_POST, etc. to obtain requested information, but these variables are not objects, but arrays. In order to process request information more flexibly and conveniently, you can

The role and significance of Request in PHP The role and significance of Request in PHP Feb 27, 2024 pm 12:54 PM

The role and significance of Request in PHP In PHP programming, Request is a mechanism for sending requests to the Web server. It plays a vital role in Web development. Request is mainly used to obtain data sent by the client, such as form submission, GET or POST request, etc. Through Request, the data input by the user can be obtained, and the data can be processed and responded to. This article will introduce the role and significance of Request in PHP and give specific code examples.

How to use context to implement request parameter verification in Go How to use context to implement request parameter verification in Go Jul 22, 2023 am 08:23 AM

How to use context to implement request parameter verification in Go Introduction: During the back-end development process, we often need to verify the request parameters to ensure the legality of the parameters. The Go language provides the context package to handle request context information. Its elegant design and simple use make it a commonly used tool. This article will introduce how to use Go's context package to implement request parameter verification and give corresponding code examples. Introduction to the context package In Go, the context package is used to deliver

See all articles