Esempio n. 1
0
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR <SendingConnection>("/sending-connection");
            app.MapSignalR <TestConnection>("/test-connection");
            app.MapSignalR <RawConnection>("/raw-connection");
            app.MapSignalR <StreamingConnection>("/streaming-connection");

            app.Use(typeof(ClaimsMiddleware));

            ConfigureSignalR(GlobalHost.DependencyResolver, GlobalHost.HubPipeline);

            app.Map("/cors", map =>
            {
                map.UseCors(CorsOptions.AllowAll);
                map.MapSignalR <RawConnection>("/raw-connection");
                map.MapSignalR();
            });

            app.Map("/cookieauth", map =>
            {
                var options = new CookieAuthenticationOptions()
                {
                    AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
                    LoginPath          = CookieAuthenticationDefaults.LoginPath,
                    LogoutPath         = CookieAuthenticationDefaults.LogoutPath,
                };

                map.UseCookieAuthentication(options);

                map.Use(async(context, next) =>
                {
                    if (context.Request.Path.Value.Contains(options.LoginPath.Value))
                    {
                        if (context.Request.Method == "POST")
                        {
                            var form     = await context.Request.ReadFormAsync();
                            var userName = form["UserName"];
                            var password = form["Password"];

                            var identity = new ClaimsIdentity(options.AuthenticationType);
                            identity.AddClaim(new Claim(ClaimTypes.Name, userName));
                            context.Authentication.SignIn(identity);
                        }
                    }
                    else
                    {
                        await next();
                    }
                });

                map.MapSignalR <AuthenticatedEchoConnection>("/echo");
                map.MapSignalR();
            });

            var config = new HubConfiguration()
            {
                EnableDetailedErrors = true
            };

            app.MapSignalR(config);

            BackgroundThread.Start();
        }
Esempio n. 2
0
 protected void Application_Start(object sender, EventArgs e)
 {
     SignalRConfig.ConfigureSignalR(GlobalHost.DependencyResolver, GlobalHost.HubPipeline);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BackgroundThread.Start();
 }