【发布时间】:2017-05-14 19:15:50
【问题描述】:
我在 SignalR 中创建了一个聊天应用程序 (.NET MVC4),它在我的开发机器上运行良好。但是当我将它上传到我们的生产服务器时,我的客户端没有收到任何对“组”的调用。
当我这样做时:
var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
context.Clients.All.addOnline(profielidVan);
效果很好!但是当我这样做时:
var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
context.Clients.Group(profielidNaar).addOnline(profielidVan);
我的客户没有接到任何电话。
为了连接到正确的组,我在每个 SignalR 连接开始时调用集线器上的一个名为 Join() 的函数:
$(function () {
var chat = $.connection.Chat;
chat.client.addOnline = function (profielid) {
if ($("#profielidNaar").val() == profielid) {
var now = new Date()
$("#onlinetime").val(now);
$('#typtbericht').html('Online');
}
};
// ... code to the other jQuery functions called by SignalR ...
$.connection.hub.start().done(function () {
chat.server.join();
// ... code to the page jQuery functions (like $(window).resize) ...
}
}
以及服务器端代码:
[HubName("Chat")]
public class ChatHub : Hub
{
public Task Join()
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
Profiel_DataHelper profiel = new Profiel_DataHelper(HttpContext.Current.User.Identity.Name);
return Groups.Add(Context.ConnectionId, profiel.ProfielID.ToString());
}
else
{
return null;
}
}
...
谁能帮帮我?
【问题讨论】:
-
那么显示代码将暗示用户未经过身份验证,该站点使用什么形式的身份验证?
-
我正在使用标准的会员资格提供者身份验证。但是用户已通过身份验证,这不是问题,如果用户未通过身份验证,页面将不会显示。否则问题也会出现在我的开发机器上。
标签: c# .net asp.net-mvc-4 signalr