ASP.NET MVC OWIN and SignalR - two Startup.cs files

后端 未结 2 1097
说谎
说谎 2021-01-02 10:28

I have a problem with my project.

I use ASP.NET MVC with ASP.NET Identity 2.0 for authentication and I added SignalR to the project so now I have two Startup.cs file

相关标签:
2条回答
  • 2021-01-02 11:04

    Could you put both sets of code into one single OwinStartup file?

    namespace MCWeb_3SR
    {
        public class OwinStartup
        {
            public void Configuration(IAppBuilder app)
            {
                ConfigureAuth(app);
    
                var heartBeat = GlobalHost.DependencyResolver.Resolve<ITransportHeartbeat>();
                var monitor = new PresenceMonitor(heartBeat);
                monitor.StartMonitoring();
    
                // Any connection or hub wire up and configuration should go here
                app.MapSignalR();
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-02 11:22

    Move your signalr startup file to the App_Start folder and rename it to Startup.SignalR.cs. It should have this content, note that the Configure method has been renamed to ConfigureSignalR:

    namespace MCWeb_3SR
    {
      public partial class Startup
      {
        public void ConfigureSignalR(IAppBuilder app) {
          var heartBeat = GlobalHost.DependencyResolver.Resolve<ITransportHeartbeat>(); 
    
          var monitor = new PresenceMonitor(heartBeat); 
          monitor.StartMonitoring(); 
    
    
          // Any connection or hub wire up and configuration should go here 
          app.MapSignalR();
        }
      }
    }
    

    Now in the Startup.cs file at the root of your project, add a ConfigureSignalR(app) call right after ConfigureAuth(app):

    [assembly: OwinStartup(typeof(MCWeb_3SR.Startup))]
    namespace MCWeb_3SR
    {
      public partial class Startup
      {
        public void Configuration(IAppBuilder app) {
          ConfigureAuth(app);
          ConfigureSignalR(app);
        }
      }
    }
    

    As long as all of the Startup partial classes have the same namespace, this should work.

    0 讨论(0)
提交回复
热议问题