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

后端 未结 2 1099
说谎
说谎 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条回答
  •  -上瘾入骨i
    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(); 
    
          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.

提交回复
热议问题