1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using Microsoft.AspNet.SignalR;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
[assembly: OwinStartup(typeof(VueWebApi.App_Start.Startup))]
namespace VueWebApi.App_Start
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // 有关如何配置应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkID=316888
            //允许跨域
            //app.UseCors(CorsOptions.AllowAll);
            //app.MapSignalR("Hubs/chatHub", new HubConfiguration());
            //app.MapSignalR();
            //自己设定访问路径,同时设置Hub配置项,无需指定启动的Hub类,因为它们被自动识别
 
            // 连接标识
            //app.Map("/signalr", map =>
            //{
            //     //跨域
            //    map.UseCors(CorsOptions.AllowAll);
            //    var hubConfiguration = new HubConfiguration
            //    {
            //        EnableJSONP = true
            //    };
            //     //启动配置
            //     map.RunSignalR(hubConfiguration);
            //});
 
 
            // 连接标识
            app.Map("/signalr", map =>
            {
                //跨域
                map.UseCors(CorsOptions.AllowAll);
                var hubConfiguration = new HubConfiguration
                {
                    EnableJSONP = true
                };
                //启动配置
                map.RunSignalR(hubConfiguration);
            });
        }
    }
}