我可以调试OnConnected在SignalR中心的方法? [英] Can I debug OnConnected method in SignalR Hub?

查看:1188
本文介绍了我可以调试OnConnected在SignalR中心的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集线器我的asp.net项目中,我重写OnConnected的方法,我可以调试code中的OnConnected方法里面呢?我把一个断点,但它不是射击。

 公共类ConsultasHub:集线器
    {
        公众覆盖任务OnConnected()
        {
            //这里断点
            //一些code
            // [...]
            返回base.OnConnected();
        }    }
}


解决方案

这是一个棘手的。通过设计,如果你没有任何订阅到集线器,则客户端无法从服务器获取任何消息使OnConnected将不会被调用。
我试过如下:

使用系统;
使用的System.Web;
使用Microsoft.AspNet.SignalR;
使用System.Web.Script.Serialization;
使用System.Collections.Generic;
使用System.Threading.Tasks;公共类ConsultasHub:中心{
    公众覆盖任务OnConnected(){
        //这里断点
        //一些code
        // [...]
        返回base.OnConnected();
    }
}

电话:

VAR聊天= $ .connection.consultasHub;的console.log(连接...);
$ .connection.hub.start()。完成(功能(){
    的console.log(完成);
});

而OnConnected不开枪,控制台消息完成。被写入。

但是,一旦我有一个事件和订阅,

使用系统

;
使用的System.Web;
使用Microsoft.AspNet.SignalR;
使用System.Web.Script.Serialization;
使用System.Collections.Generic;
使用System.Threading.Tasks;公共类ConsultasHub:中心{
    公众覆盖任务OnConnected(){
        //这里断点
        //一些code
        // [...]
        返回base.OnConnected();
    }    公共无效SendMessage函数(字符串消息){
        Clients.All.message(消息);
    }
}

VAR聊天= $ .connection.consultasHub;
chat.client.message =功能(消息){
    的console.log(信息:+消息);
};的console.log(连接...);
$ .connection.hub.start()。完成(功能(){
    的console.log(完成);
});

OnConnected解雇(断点到达)。试试看!
我希望它能帮助。

I have a Hub inside my asp.net project , and I overridden the OnConnected method, can I debug the code inside the OnConnected method? I put a breakpoint but it's not firing.

    public class ConsultasHub : Hub
    {                    
        public override Task OnConnected()
        {
            //breakpoint here
            //some code
            //[...]
            return base.OnConnected();
        }

    }
}

解决方案

This is a tricky one. By design, if you don't have any subscriptions to the hub, then the client can't get any messages from server so the OnConnected won't get called. I tried the following:

using System;
using System.Web;
using Microsoft.AspNet.SignalR;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Threading.Tasks;

public class ConsultasHub : Hub {
    public override Task OnConnected() {
        //breakpoint here
        //some code
        //[...]
        return base.OnConnected();
    }
}

call:

var chat = $.connection.consultasHub;

console.log("connecting...");
$.connection.hub.start().done(function () {
    console.log("done.");
});

And the OnConnected not fired, console message 'done.' is written.

However, once I have an event and a subscription,

using System;
using System.Web;
using Microsoft.AspNet.SignalR;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Threading.Tasks;

public class ConsultasHub : Hub {
    public override Task OnConnected() {
        //breakpoint here
        //some code
        //[...]
        return base.OnConnected();
    }

    public void SendMessage( string message ) {
        Clients.All.message(message);
    }
}   

var chat = $.connection.consultasHub;
chat.client.message = function (message) {
    console.log("message: " + message);
};

console.log("connecting...");
$.connection.hub.start().done(function () {
    console.log("done.");
});

OnConnected fired (breakpoint reached). Try it out! I Hope it helps.

这篇关于我可以调试OnConnected在SignalR中心的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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