How to use Session in SignalR Hub class? ASP.NET MVC
Here is my code:
public override Task OnConnected()
{
if (HttpContext.Current.Session["US_ID"] != null)
{
lstUsers.Add(Context.ConnectionId, new USER { US_ID = HttpContext.Current.Session["US_ID"].ToString() });
Clients.All.BroadcastConnections(lstUsers);
}
return base.OnConnected();
}
Error: Object reference not set to an instance of an object.
Error in this line if (HttpContext.Current.Session["US_ID"] != null)
How to solve it?