Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between HttpContext and HttpRequest?

Tags:

c#

.net

asp.net

HttpRequest represents http client on server as per http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx it "Enables ASP.NET to read the HTTP values sent by a client during a Web request."

It was my understanding that HttpContext also does the same. As per MSDN http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx it is "Encapsulates all HTTP-specific information about an individual HTTP request."

What we need to class for this ? How are they different and which should be used when ?

I am not able to figure out what is difference between them ? Can you please guide and help.

Thanks

like image 579
Toubi Avatar asked Sep 26 '13 00:09

Toubi


2 Answers

HttpRequest is a subset of HttpContext. In other words, the HttpContext includes the response, the request, and various other data that's not relevant to a specific request or response; such as the web application, cached data, server settings and variables, session state, the authenticated user, etc.

For example:

HttpContext.Current.Request // This is the current HttpRequest object
HttpContext.Current.Response // This is the current HttpResponse object

I think if you dig around the APIs of each, you'll quickly understand how things are organized.

like image 146
Mike Christensen Avatar answered Sep 28 '22 07:09

Mike Christensen


HttpContext, Encapsulates all HTTP-specific information about an individual HTTP request while HttpRequest is just one of the information within the context.

Take a look at API docs, you understand more

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx

like image 44
Stay Foolish Avatar answered Sep 28 '22 09:09

Stay Foolish