标签: signalr-hub

signalR跟踪连接的用户

我需要检查特定用户是否仍然连接.

我有以下用于跟踪用户的HashSet:

public static class UserHandler
{
    public static HashSet<string> ConnectedIds = new HashSet<string>();
}
Run Code Online (Sandbox Code Playgroud)

因此断开连接:

    public override Task OnDisconnected()
    {
        UserHandler.ConnectedIds.Remove(this.Context.ConnectionId);
        if (UserHandler.ConnectedIds.Count == 0)
        {
               // STOP TASK -> SET CANCELLATION
        }
        return base.OnDisconnected();
    }
Run Code Online (Sandbox Code Playgroud)

并在连接上:

    public override Task OnConnected()
    {
        Logger.Log.file.Info("[TaskActionStatus HUB => OnConnected] Start");

        UserHandler.ConnectedIds.Add(this.Context.ConnectionId);

        // start task only if at least one listener
        if (UserHandler.ConnectedIds.Count < 2)
        {
            // START A TASK -> (WHILE LOOP THAT GETS DATA FROM DB EVERY 2 SEC)
        }

        return …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc signalr signalr-hub

5
推荐指数
1
解决办法
4164
查看次数

客户端功能未被称为SignalR

控制器类其中定义了Hub

    public abstract class MonitoringProfileLogChartController : Croem.NotificationManager.Website.Base.BaseController.BaseController
        {

            public ActionResult Index()
            {
                BusinessLogicReturn result = new ProcessBusinessLogic.Logic().GetRegisteredContexts();
                return base.TransalateToAction(result);
            }
            public ActionResult LiveMonitoringProfileLogChart()
            {
                return View();
            }
            public ActionResult test()
            {
                return View();
            }

**below is rest of the code of controller where our focus should be**


  public JsonResult GetMonitoringProfileLogChart(string FromDate, string ToDate, int ContextId)
        {
            BusinessLogicReturn result = new ProcessBusinessLogic.Logic().GetMonitoringProfileLogChart(FromDate, ToDate, ContextId);
            return Json(result.Model, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetMonitoringProfileLiveLogChart(string FromTime, string ToTime, string DataMinutes)
        {
            BusinessLogicReturn result = new …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net-mvc-4 signalr signalr-hub signalr.client

5
推荐指数
1
解决办法
9154
查看次数

在MVC 5应用程序中使用autofac注入SignalR集线器的依赖项

我正在尝试将SignalR 2引入现有项目,在该项目中,所有依赖项注入均使用autofac执行,所有依赖项配置均在Global.asax中执行。我找到了将SignalR与autofac一起使用的Autofac.SignalR软件包及其随附的文档

我按照提供的文档中的示例进行操作,并遵循使用RegisterHubs函数而不是定义我个人的集线器依赖项的建议。

不幸的是,当尝试从lifetimeScope解析依赖项时,我的Hub类收到以下运行时错误

Autofac.Core.DependencyResolutionException was unhandled by user code
HResult=-2146233088
Message=No scope with a Tag matching 'AutofacWebRequest' is
visible from the scope in which instance was requested.
This generally indicates that a component registered as per-HTTP
request is being requested by a SingleInstance() component
(or a similar scenario.) Under the web integration always request
dependencies from the DependencyResolver.Current or 
ILifetimeScopeProvider.RequestLifetime, never from the container itself.
Run Code Online (Sandbox Code Playgroud)

我无法获得DependencyResolver.Current或ILifeTimeScopeProvider为我工作。

我的依赖配置如下

var builder = new ContainerBuilder();
    .RegisterControllers(typeof (MvcApplication).Assembly);
    .RegisterHubs(Assembly.GetExecutingAssembly());
    ...
var …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc dependency-injection autofac signalr signalr-hub

5
推荐指数
1
解决办法
3160
查看次数

Azure Web作业中的Signalr自托管Hub需要提升吗?

我想在连续的Azure Web作业中使用SignalR自托管项目.但是当我尝试运行它时,我收到以下错误:

[07/11/2014 10:58:44 > cbec50: SYS INFO] Status changed to Running
[07/11/2014 10:58:45 > cbec50: ERR ] Unhandled Exception: System.Reflection.TargetInvocationException: 
Exception has been thrown by the target of an invocation. ---> System.Net.HttpListenerException: Access is denied
Run Code Online (Sandbox Code Playgroud)

我想控制台应用程序需要以提升的权限运行.有没有办法让这个工作?

先决条件:

Install-Package Microsoft.Azure.Jobs -pre
Install-Package Microsoft.AspNet.SignalR.SelfHost
Run Code Online (Sandbox Code Playgroud)

完整来源:

using System;
using Microsoft.Azure.Jobs;
using Microsoft.Owin.Hosting;
using Owin;

namespace ConsoleApplication2
{
    class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            using (WebApp.Start<Startup>("http://localhost:8080/"))
            {
                Console.WriteLine("Server running …
Run Code Online (Sandbox Code Playgroud)

azure signalr signalr-hub azure-webjobs

5
推荐指数
1
解决办法
1104
查看次数

SignalR 2不生成/ signalr/hubs

这是页面:

        <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/jquery.signalR-2.1.2.min.js"></script>
    <!--Reference the autogenerated SignalR hub script. -->
    <script src="~/signalr/hubs"></script>
    <!--SignalR script to update the chat page and send messages.-->
    <script>
        $(function () {
            // Reference the auto-generated proxy for the hub.
            var notification = $.connection.notificationHub;
            // Create a function that the hub can call back to display messages.
            notification.client.addNewMessage = function (message) {
                // Add the message to the page.
                $('#discussion').append('<li><strong>'
                    + '</strong>: ' + htmlEncode(message) + '</li>');
            };
            // Set initial focus to message …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc signalr signalr-hub signalr.client

5
推荐指数
1
解决办法
1万
查看次数

在集线器上下文之外的SignalR集线器中调用Caller方法

我有一个关于SignalR的Caller方法的问题.在hub方法中,我们可以像这样调用客户端函数.

Clients.Caller.addContosoChatMessageToPage(name, message);
Run Code Online (Sandbox Code Playgroud)

但是当我用它从集线器上下文之外调用它时,它找不到或没有实现?像这样..

 var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
 context.Clients.Caller.reportProgress(recordCount,totalCount);
Run Code Online (Sandbox Code Playgroud)

有人可以在这部分启发我,还是有其他方法来实现它..现在我用来实现这一点

 var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
 context.Clients.User(CurrentUser.Usernm).reportProgress(recordCount,totalCount);
Run Code Online (Sandbox Code Playgroud)

但现在我们不是基于声明的身份验证,因此如果记录相同的usernm将会出现问题.

asp.net signalr signalr-hub

5
推荐指数
1
解决办法
4896
查看次数

SignalR强类型集线器TypeLoadException

当我使用强类型集线器时,我遇到了TypeLoadException.我的界面是:

public interface IClientCallback
{
    void callback<T>(T msg, string eventType);
    void test(string msg, string eventType); 
}
Run Code Online (Sandbox Code Playgroud)

所有方法都在单个接口中,并且接口不从任何其他接口继承.

我的Hub类是:

public class ServiceHub : Hub<IClientCallback>
{
    public static readonly string ServiceHubName = "ServiceHub";

    public void Register(string name, string eventType)
    {
        Clients.All.test("hello", "world");
    }
}
Run Code Online (Sandbox Code Playgroud)

当我使用我的客户端应用程序在集线器上调用Register方法时,在Hub应用程序上,当它在Clients.All.test(...)时收到异常:

TypeLoadException方法'Microsoft.AspNet.SignalR.Hubs.TypedClientBuilder.IClientCallbackImpl'中的方法'callback'来自程序集'Microsoft.AspNet.SignalR.Hubs.TypedClientBuilder,Version = 0.0.0.0,Culture = neutral,PublicKeyToken = null'没有一个实现.

我无法缩小导致此异常的确切原因.一点帮助或建议将不胜感激.

c# signalr signalr-hub

5
推荐指数
2
解决办法
385
查看次数

SignalR集线器和Identity.Clams

我正在使用SignalR从服务器(Asp.net MVC)向客户端发送通知,并且在我的OnConnected()方法中,我用登录名(电子邮件)注册了用户:

public override Task OnConnected()
{
string userName = Context.User.Identity.Name;
string connectionId = Context.ConnectionId;
Groups.Add(connectionId, userName);
return base.OnConnected();
}
Run Code Online (Sandbox Code Playgroud)

现在,我想使用accountId代替名称,然后尝试使用Identity.Claims。在控制器的Login方法中,我创建了新的ClaimsIdentity

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginViewModel model)
{
----

var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, model.Email), }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role);

identity.AddClaim(new Claim(ClaimTypes.Role, "guest"));
identity.AddClaim(new Claim(ClaimTypes.GivenName, "A Person"));
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, validation.AccountId.ToString())); //from db

AuthenticationManager.SignIn(new AuthenticationProperties
{ IsPersistent = true}, identity);

AuthenticationManager.SignIn(identity);

-----
}

private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}
Run Code Online (Sandbox Code Playgroud)

我无法使用以下方法在Hub的OnConnected方法内访问我的ClaimsIdentity:

var claim = ((ClaimsIdentity)Context.User.Identity).FindFirst(ClaimTypes.NameIdentifier); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc signalr signalr-hub

5
推荐指数
1
解决办法
2013
查看次数

在SignalR Core中更改全局设置配置

我正在使用带有ASP.Net Core的SignalR Core.

我想重写GlobalHost设置signalR.

我得到这个 -

protected void Application_Start(object sender, EventArgs e)
{
    // Make long polling connections wait a maximum of 110 seconds for a
    // response. When that time expires, trigger a timeout command and
    // make the client reconnect.
    GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);

    // Wait a maximum of 30 seconds after a transport connection is lost
    // before raising the Disconnected event to terminate the SignalR connection.
    GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);

    // For …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc signalr signalr-hub asp.net-core-mvc asp.net-core

5
推荐指数
1
解决办法
1451
查看次数

确定信号R连接状态,而不广播Clients.All.someMethod()并炸毁客户端资源

我担心Clients.All在我的C#Signal R集线器类中使用

Clients.All.setConnectionStatus(profileId, true);
Run Code Online (Sandbox Code Playgroud)

我在两者中调用它OnConnected()OnDisconnected(bool stopCalled) 显示我登录用户的在线状态. OnDisconnected()并不是那么糟糕,因为只有在有人实际注销时才会被调用

恩.

public override Task OnConnected()
{
   string profileId = Context.User.Identity.Name;
   _connections.Add(profileId, Context.ConnectionId);
    Clients.All.setConnectionStatus(profileId, true);
    return base.OnConnected();
 }

public override Task OnDisconnected(bool stopCalled)
{
    string profileId = Context.User.Identity.Name;
    _connections.Remove(profileId, Context.ConnectionId);
    if (stopCalled == false) // log off only
        Clients.All.setConnectionStatus(profileId, false);
     return base.OnDisconnected(stopCalled);
}
Run Code Online (Sandbox Code Playgroud)

我担心 - >用浏览器中不断运行的javascript代码炸毁用户机器客户端!

场景 - >如果我有~~ 1000个在线用户并登录到不同的页面,我将向他们所有人发送信号R连接 Clients.All.setConnectionStatus(profileId, true);

在javascript集线器中看起来像下面这可能很容易最终炸毁用户浏览器,因为它将不断接收这些广播连接状态调用!

scope.chat = $.connection.chatHub;

// Receive and set the connection status
scope.chat.client.setConnectionStatus = function(profileId, isConnected) …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net-mvc signalr signalr-hub signalr.client

5
推荐指数
1
解决办法
207
查看次数