Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
05-May-2025The
HttpRequestclass in C# (specifically in ASP.NET) represents the incoming HTTP request from the client (browser) to the server. It is used to access form data, query strings, headers, cookies, request type, and other request-related info.Namespace
You access it in ASP.NET MVC via:
In Web Forms:
Class Overview
This class encapsulates all HTTP-specific information about a single HTTP request.
Common Properties
HttpMethodGET,POST,PUT,DELETE, etc.UrlRawUrlQueryString?id=5)FormHeadersCookiesUserAgentContentTypeInputStreamFilesIsAuthenticatedExamples
Read Query String Value
Read Form Data (POST)
Get Full URL and Method
Get Client IP Address
Access Uploaded File
Access Request Headers
Use in ASP.NET MVC
In MVC,
Requestis of typeHttpRequestBase, which is an abstracted/testable version ofHttpRequest.You can still do:
Summary Table
Request.HttpMethodRequest.QueryString["key"]Request.Form["field"]Request.Files["name"]Request.UserHostAddressRequest.Headers["HeaderName"]Request.Cookies["cookieName"]