HttpRequestContext vs HttpContext

1.6k views Asked by At

I have a question regarding HttpRequestMessage and HttpContext.

I am attempting to use web sockets in my project and have seen in a lot of examples to use the HttpContext.IsWebSocketRequest property and the HttpContext.AcceptWebSocketRequest method to check to see if the HTTP request that comes in is a web socket upgrade request or not (Using WebSocket in .NET 4.5, and Getting .NET 4.5 WebSockets Working).

The issue I am having is that my controller than handles the HTTP GET request inherits from ApiController and the only thing that I seem to have access to when a request comes in is the HttpRequestMessage.GetRequestContext(). The HttpContext.Current where the web socket properties and methods I need live currently do exist in context it says.

My thought is that when the request comes in a new thread is spun up to handle the request, but I am unsure what to do. What can I do to get access to this HttpContext.Current object that I need so I can have web socket functionality?

So to sum up, what I want to achieve is something along the lines of:

if(HttpContext.Current.IsWebSocketRequest() == true){
    Console.WriteLine("Yay!");
}

But I get a HttpContext does not exist in the current context error.

0

There are 0 answers