1

Recently, I have downloaded and integrated the sample ChatJS MVC app to my application from http://www.chatjs.net/ site which uses ChatJs and SignalR2.0. I am trying to use my application session values (userid) in ChatHub.cs class (which inherits from SignalR Hub class). In this class when I tried to access Session UserId of my application, I am getting an error as "Object reference not set to an instance of an object", it is returning null. I am able to access the same UserId session value in HomeController.cs (Controller class).

I saw in the below link which talks about my problem (also pasted the text after the link) and looks like SignalR

doesn't support the ASP.NET Session state. http://www.asp.net/signalr/overview/signalr-20/troubleshooting-and-debugging/troubleshooting

"HTTPContext.Current.Session is null.This behavior is by design. SignalR does not support the ASP.NET session state, since enabling the session state would break duplex messaging."

In my application so far we were able to use the Session values without any problem. I am stuck here as I need do so many db calls and for which I need to pass User session ID and other session values. Normally we rely on Session to provide the user-specific information.

Is there any alternative to Session OR any other way to get the User-specific information like UserId,etc. Need your help here at the earliest.

Thanks in Advance.

1 Answers1

1

User-specific information such as user ID should probably be stored in the same context that you are managing user authentication, not in the session state. This will also solve other problems you may have with session state (i.e., scaling).

If you are using ASP.NET forms authentication, you can use membership and profiles to store information about a user. You can read all about membership and profiles here.

Greg Ennis
  • 14,917
  • 2
  • 69
  • 74