HTTPContext.Current.Session是NUL在SignalR ...需要备用会话状态,同时使用SignalR [英] HTTPContext.Current.Session is nul in SignalR...need alternate to Session state while using SignalR

查看:686
本文介绍了HTTPContext.Current.Session是NUL在SignalR ...需要备用会话状态,同时使用SignalR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

近日,笔者从 http://www.chatjs.net下载并集成了样品ChatJS MVC应用程序,以我的应用程序/它采用ChatJs和SignalR2.0 网站。我试图使用ChatHub.cs类我的应用程序会话值(用户ID)(从SignalR集线器类继承)。在这个类中,当我试图访问我的应用程序的用户ID会议,我得到一个错误不设置到对象的实例对象引用时,返回null。我能够访问同一个用户ID会议HomeController.cs值(控制器类)。

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).

我在下面的链接,谈论我的问题(也粘贴此链接后文),看起来像SignalR看到

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

不支持ASP.NET会话状态。
http://www.asp.net/signalr/overview/signalr-20/troubleshooting-and-debugging/troubleshooting

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

HTTPContext.Current.Session是null.This行为是由设计。SignalR不支持ASP.NET会话状态,因为使会话状态将打破双工消息。

"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."

在我的应用程序,到目前为止,我们能够使用Session值没有任何问题。我坚持在这里,因为我需要做这么多分贝呼吁和我需要传递用户的会话ID和其他会话值。通常情况下,我们依靠会话提供用户特定的信息。

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.

有没有替代会话或任何其他方式来获得用户ID一样,等用户特定的信息。这里需要你的帮助在最早的。

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.

先谢谢了。

推荐答案

用户特定的信息如用户ID或许应该被存放​​在您管理用户身份验证,而不是在会话状态相同的上下文。这也将解决其他问题,您可能与会话状态(即洗牙)。

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).

如果您正在使用ASP.NET窗体身份验证,可以使用会员资格和配置文件来存储有关用户的信息。你可以阅读所有关于会员资格和型材这里

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.

这篇关于HTTPContext.Current.Session是NUL在SignalR ...需要备用会话状态,同时使用SignalR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆