I have an application that is written using c# on the top of Asp.Net MVC 5 Framework.
I am using SignalR 2.2.2 to create WebSocket communication between the browser and the server to push messages from the server to the browser.
However, I need to be able to access my ClaimsIdentity
object for the logged in user so I can determine what messages to podcast.
Typically, I would access the identity claims like so
IPrincipal user = System.Web.HttpContext.Current.User
IIdentity identity = user.Identity;
var claims = (IEnumerable<Claim>)identity.Claims;
However, this line System.Web.HttpContext.Current
returns null; preventing me from obtaining the currently logged in user.
I am guessing that SignalR create a synchronous connection which is why System.Web.HttpContext.Current
is null.
I also try to use the HubCallerContex
as suggested by this SO Question but the Context
object is also null.
System.Web.HttpContextBase httpContext = Context.Request.GetHttpContext();
How can I correctly access the user claims with in my Hub?
I added the following key to my appSettings
in my Web.config as I am using Framework 4.5.1
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>