Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Custom SignalR Hub OnConnected not firing (Logger.Debug messages not appearing in log file) #8544


User avatar
0
carelearning created

Dear Volosoft Representative,

Steps to reproduce:

  1. Clone latest AbpZero github
  2. Configure The Project
  3. Create sample Tenant demo
  4. Create one user jdoe for new Tenant demo
  5. Create new controller Test under MPA area.
  6. Create new Index view for Test controller.
  7. Create Hubs folder in root of Web project
  8. Create ManagementHub under Hubs folder. Code
  9. Login and navigate /mpa/test/index
  10. Check app_data\logs\logs.txt Expected messages are not appearing
ManagementHub.cs
namespace MyCompanyName.AbpZeroTemplate.Web.Hubs
{
    using Abp.Dependency;
    using Abp.Runtime.Session;
    using Castle.Core.Logging;
    using Microsoft.AspNet.SignalR;
    using Microsoft.AspNet.SignalR.Hubs;
    using System.Threading.Tasks;

    [HubName("management")]
    public class ManagementHub: Hub, ITransientDependency
    {
        public IAbpSession AbpSession { get; set; }
        public ILogger Logger { get; set; }

        public ManagementHub()
        {
            AbpSession = NullAbpSession.Instance;
            Logger = NullLogger.Instance;
        }

        public override Task OnConnected()
        {
            await base.OnConnected();
            Logger.Debug($"A client connected to ManagementHub: {Context.ConnectionId}.");
            return Task.FromResult(0);
        }

        public override Task OnDisconnected(bool stopCalled)
        {
            await base.OnDisconnected(stopCalled);
            Logger.Debug($"A client disconnected to ManagementHub: {Context.ConnectionId}.");
            return Task.FromResult(0);
        }
    }
}
TestController.cs
using System.Web.Mvc;

namespace MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Controllers
{
    public class TestController : Controller
    {
        // GET: Mpa/Test
        public ActionResult Index()
        {
            return View("Index");
        }
    }
}
Index.cshtml
@{
    ViewBag.Title = "title";
}

<h2>Welcome to TEST</h2>

1 Answer(s)
  • User Avatar
    0
    carelearning created

    We worked around the issue by extracting functionality into two separate hub classes and registered them independently.

    We changed our IOC registrations in AbpZeroTemplateWebModule in PreInitialize from:

    Old Way

      IocManager.IocContainer.Register(
            Component.For<IMessage<string>, IStatusMessage>()
                .ImplementedBy<ManagementHub>()
                .LifestyleSingleton()
      );
    

    New Way

      IocManager.Register<IMessage, ManagementHub>();
      IocManager.Register<IStatusMessage, AgentHub>();
    

    The AgentHub's OnConnected and OnDisconnected is not firing, however the ManagementHub now is. This works for our needs.