简体   繁体   English

如何在ASP MVC中使用Global.asax而非Startup.cs配置SignalR?

[英]How to configure SignalR with Global.asax instead of Startup.cs in ASP MVC?

SignalR Requires Owin Startup Class, but my application works with Global.asax class. SignalR需要Owin启动类,但是我的应用程序可以使用Global.asax类。

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

if I add the startup class, my asp MVC project will have two start classes (global and startup), is it OK? 如果添加启动类,我的ASP MVC项目将有两个启动类(全局和启动),可以吗? or I should only apply one of them and move my global class to startup class? 还是只应应用其中之一并将我的全局课程移至启动课程?

You can mark which class in an assembly will be automatically used by Owin in the startup. 您可以标记程序集中的哪个类在启动时由Owin自动使用。

In my example, I declared it in the Startup and pointed to it using OwinStartup eg 在我的示例中,我在Startup声明了它,并使用OwinStartup指向了它,例如

using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using System.Net;
[assembly: OwinStartup(typeof(YourProject.Startup))]


namespace YourProject
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var hubConfiguration = new HubConfiguration
            {
                EnableDetailedErrors = true
            };
            app.MapSignalR(hubConfiguration);
        }
    }
}

If you are using Owin , you must use the Startup class instead of the Global.asax . 如果使用的是Owin ,则必须使用Startup类而不是Global.asax

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM