HttpRequestContext vs HttpContext

I have a question regarding HttpRequestMessage

and HttpContext

.

I'm trying to use websockets in my project and have seen in many examples using a property HttpContext.IsWebSocketRequest

and method HttpContext.AcceptWebSocketRequest

to check if an HTTP request is included in a websocket refresh request (not) ( Using WebSocket in .NET 4.5 and Getting .NET 4.5 Working with WebSockets ).

The problem is that my controller inherits from what it handles the HTTP GET request ApiController

and the only thing I seem to have access to when the request comes in is HttpRequestMessage.GetRequestContext()

. HttpContext.Current

where the websocket properties and methods I need currently exist in the context it says.

My thought is that when a request arrives on a new thread, it is deployed to handle the request, but I'm not sure what to do. What can I do to access this object HttpContext.Current

that I need so that I can have the websocket functionality?

So, to summarize, I want to achieve something like:

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

      

But I am getting HttpContext does not exist in the current context error.

+3


source to share





All Articles