Last post Apr 08, 2013 01:43 AM by davidfowl
Apr 04, 2013 10:05 AM|alexanderTar|LINK
I want create private chat with roles, which use the SignalR technology. For this I used System.Web.Security.Roles mechanism which use HttpContext. When I disconnect from hub i can't get information about role (Roles.GetRolesForUser()). Why? How I can resolve
public class MessengerHub : Hub
public override Task OnConnected()
var context = HttpContext.Current; //<--- not null
var role = Roles.GetRolesForUser();//<--- returned role
public override Task OnDisconnected()
var context = HttpContext.Current; //<--- null!!!!
var role = Roles.GetRolesForUser();//<--- throwed httpContext not defined
Apr 08, 2013 01:43 AM|davidfowl|LINK
You really should use HttpContext.Current *anywhere*, it's a shame that code assumes there's an HttpContext as you found out there isn't and that's completely by design. OnDisconnected is called from a non request thread hence there's no HttpContext. To
access the http context, you can use the extension method Context.Request.GetHttpContext().
As for APIs that assume you're on a request thread, you're out of luck.