The value that the receiving client sent over the HTTP request (Httprequestbase/httprequest, Httpcontextbase/httpconext, HttpContext.Current)

Source: Internet
Author: User
Tags httpcontext

Although it is essential to know how ASP. NET MVC programs receive information from client HTTP, there is some ambiguity about HTTP request flow and data transfer mechanisms, just a little bit today.

Take a look at the client code:

<formAction= "Default"Method= "POST" >User name:<inputtype= "text"name= "UserName" />    <inputtype= "Submit"value= "Submit" /></form>the user name you entered is: @ViewBag. UserName

Take a look at the server-side code:

 public  class   testcontroller:controller{  [HttpGet]  
   
    public  
     ActionResult Default () { 
    return  
     View (); } [HttpPost]  
    public  actionresult Default (
     String  
     ABC) {viewbag.username  = Request[
     " 
    username  
    "  
     ];         
or
Viewbag.username = httpcontext.request["UserName"];
return View (); }}

It is possible to use request["XXX" in the controller directly to receive the form items because the current controller inherits the request property of type Httprequestbase from the Controler,controler class. Since TestController inherits from the controller class here, it also has a request property of type httprequestbase inside it. This request property stores information about the client for the current HTTP request (such as the form information above).

Here the Request property is the Httprequestbase type, and when we need to hand over the task receiving the client value to a class instance other than the current controller object, you can pass the request property of the current controller object as an argument to another class instance.

Also, notice that there is a HttpContext attribute of type httpcontextbase in the controller definition.

The value that the receiving client sent over the HTTP request (Httprequestbase/httprequest, Httpcontextbase/httpconext, HttpContext.Current)

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.