ASP   « Prev  Next »


Lesson 4ASP Request Object
Objective Describe the ASP Request object.

ASP Request Object

In an earlier lesson, we explained the interactions between the browser (or client) and the server. Since the browser starts the dialog, we called the client side[1] the request and the server's reply the response. The ASP Request object represents the client-side request and any user data sent as part of that request. The server's task in receiving a request is to:
  1. Identify the data
  2. Store and/or process the received data
  3. Respond appropriately

The Request object makes all the information sent from the user's browser, including binary files sent as file uploads, available to the server . Some information, such as the browser type and operating system, may be used by the server to send browser-specific versions of Web pages to the user .


Understanding the HttpRequest Object in ASP.NET Core 9.0

In modern web development with ASP.NET Core 9.0, the interaction between the client (typically a browser or mobile app) and the server follows the same fundamental principle as before: the client initiates a request, and the server issues a response. These interactions are handled through HTTP, with ASP.NET Core exposing powerful abstractions to access request and response data.
The `HttpRequest` object in ASP.NET Core represents the incoming request from the client. It encapsulates all the data associated with that request, including:
  • Query strings and route data
  • Form fields (including multipart form data for file uploads)
  • HTTP headers (including user-agent data like browser and OS)
  • Cookies
  • Uploaded files via `Request.Form.Files`
  • Raw body content (for APIs using JSON or XML)
Within an ASP.NET Core controller or Razor page, the server uses the `Request` object to:
  1. Access and interpret user data (e.g., `Request.Query["id"]` or `Request.Form["email"]`)
  2. Parse uploaded files using `Request.Form.Files`
  3. Read metadata such as `Request.Headers["User-Agent"]` for adaptive UI or compatibility handling
  4. Respond intelligently based on the request method, content type, or route parameters

ASP.NET Core is middleware-driven and cross-platform, enabling request processing pipelines that are more efficient and customizable than classic ASP. Additionally, the framework supports dependency injection, asynchronous processing, and rich support for REST APIs—making the `HttpRequest` object a foundational tool in both traditional and modern web app architectures.


Uses of the `HttpRequest` Object in ASP.NET Core 9.0

Here's the rewritten version for **ASP.NET Core 9.0 in the year 2025**:
While the `HttpRequest` object in ASP.NET Core 9.0 offers a broad range of features for handling client requests, it is most commonly used for the following four purposes:
  1. Reading Browser Cookies
    • Access cookies sent by the client using the Request.Cookies collection:
      var userId = Request.Cookies["UserId"];
              
  2. Reading Query Strings
    • Retrieve URL query parameters via the Request.Query collection:
      var searchTerm = Request.Query["q"];
              
  3. Reading HTML <form> Input Fields
    • Access form data submitted via POST requests through the Request.Form collection:
      var email = Request.Form["email"];
              
  4. Reading HTTP Header Information (Formerly "Server Variables")
    • Use the Request.Headers dictionary to access HTTP headers previously known as "server variables" in Classic ASP:
      var userAgent = Request.Headers["User-Agent"];
      var referer = Request.Headers["Referer"];
              


Unlike Classic ASP, ASP.NET Core provides strong typing, asynchronous support, and dependency injection—making the `HttpRequest` object more secure, scalable, and adaptable to modern web application needs.
Although the Request object has many features, it is most commonly used for four tasks:
  1. Reading data from browser cookies (Request.Cookies)
  2. Reading query strings (Request.Query)
  3. Reading input HTML <FORM> elements (Request.Form)
  4. Reading and storing Server Variables, the header information from browser requests (Request.ServerVariables)
Upcoming lessons will illustrate each of these uses of the Request object.

  • Summary of the Request Object
    Request Summary
    Request[.collection|property|method](variable)
    Collections
    ClientCertificate Fields stored in the client certificate, used with encrypted credentials
    Cookies Cookies sent by the client browser
    Form Form elements in the body of the client request
    QueryString All of the variables (and their values) in the query string sent from the client
    ServerVariables Environment variables
    Events
    No events defined --
    Methods
    BinaryRead Data included by a POST request
    Properties
    TotalBytes Total number of bytes the client is sending in the body of the request (you can read this property's value, but youcan't set it)

The next lesson describes how the Request object processes HTML Form data.


[1]Client-side: Running on a client, rather than a server. For example, a Java applet embedded in an HTML page runs on the client computer, not the server that sends out the page.

SEMrush Software