What are differences between these classes in ASP.NET? As I discovered there is no inheritance relationship between these classes.
Below code returns an instance of HttpRequestWrapper
which is a
HttpRequestBase
and has a
HttpRequest
HttpRequestMessage request = ...;
HttpRequestBase reqBase = (request.Properties["MS_HttpContext"] as HttpContextWrapper).Request;
// do somthing with reqBase.Cookies
It seems like Microsoft wanted to annoy us while reaching cookies from HttpRequestMessage.
Is it guaranteed that request.Properties["MS_HttpContext"]
will never be null?
Or think that an ajax request is handled in an action of ApiController. I can reach IP of the client with two different ways.
var ip = (request.Properties["MS_HttpContext"] as HttpContextWrapper).Request.UserHostAddress
var ip = HttpContext.Current.Request.UserHostAddress
What is the difference between these two?
Or in general, I can access same request/response data such as Cookie, Header, Requestor Info etc. in different ways. When to use which? Can we say something like "if it is an ajax request, HttpRequest is not guaranteed to work properly because of lack of something so for ajax requests we should use HttpRequestMessage instead"?