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
http c # asp.net websocket sockets


source to share


No one has answered this question yet

Check out similar questions:

1270
Why not inherit from List <T>?
325
"The Controls collection cannot be changed because the control contains blocks of code."
264
The timeout has expired. The timeout period expires before the operation completes or the server is not responding. Application has been terminated
22
Limiting WebSocket performance factors in ASP.NET 4.5?
12
Converting OwinHttpRequestContext to HttpContext? (IHttpHandler and websockets)
2
Server HttpContext compatibility?
0
Accessing HttpContext at _ViewStart
0
Consuming HttpContext Cache with streams
0
How can I get the web service method called by HttpContext?
0
C # SignalR GetHttpContext / HttpContext Response Doesn't exist



All Articles
Loading...
X
Show
Funny
Dev
Pics