Welcome to the navigation

Nisi officia dolor eiusmod eu incididunt magna reprehenderit nostrud laborum, veniam, commodo adipisicing sint anim ut exercitation ut consequat, dolore culpa aute labore lorem et. Voluptate exercitation aliqua, ad cillum ut commodo laborum, proident, velit ut amet, tempor in sed nostrud eu non consequat, fugiat laboris dolore ut id magna

Yeah, this will be replaced... But please enjoy the search!

Get or construct a HttpContextWrapper inside a Web API Controller

The HttpContextWrapper is an essential part of the ASP.NET Web API since you will be able to not only use the common HttpContext data but also lots of other useful properties and methods. It is not in general recommended to use the HttpContextWrapper in testing and mocking, in such cases you should instad use the HttpContextBase from which the HttpContextWrapper inherits.

private HttpContextWrapper GetHttpContext(HttpRequestMessage request = null)
{
    request = request ?? Request;
 
    if (request.Properties.ContainsKey("MS_HttpContext"))
    {
        return ((HttpContextWrapper)request.Properties["MS_HttpContext"]);
    }
    else if (HttpContext.Current != null)
    {
        return new HttpContextWrapper(HttpContext.Current);
    }
    else
    {
        return null;
    }
}
Please note that this portal is a BETA site , I will continuously improve all functionality and performance during the coming weeks / the author