SignalR / Chat Sample .Net Core WebSocket不在OPEN状态

时间:2018-08-22 12:05:18

标签: .net signalr

我在net core 2.1.3中有一个应用程序,我试图在该应用程序上插入一个小聊天,我已经报告了该应用程序中的示例代码,但始终会收到此消息

谢谢

enter image description here

我的startup.cs

//此方法由运行时调用。使用此方法将服务添加到容器。         公共无效ConfigureServices(IServiceCollection服务)         {

        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));


        services.AddIdentity<ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

        // Configure Identity
        services.Configure<IdentityOptions>(options =>
        {
            // Password settings
            options.Password.RequireDigit = true;
            options.Password.RequiredLength = 8;
            options.Password.RequireNonAlphanumeric = false;
            options.Password.RequireUppercase = true;
            options.Password.RequireLowercase = false;

            // Lockout settings
            options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
            options.Lockout.MaxFailedAccessAttempts = 10;

            //// Cookie settings
            //options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(150);
            //options.Cookies.ApplicationCookie.LoginPath = "/Account/LogIn";
            //options.Cookies.ApplicationCookie.LogoutPath = "/Account/LogOut";

            // User settings
            options.User.RequireUniqueEmail = true;
        });

        // Add application services.
        services.AddTransient<EmailSender, EmailSender>();
        services.AddAuthorization(options =>
        {
            options.AddPolicy("ControllerActionPolicy", policy => policy.Requirements.Add(new ControllerActionAccessRequirement()));
        });
        services.AddScoped<IAuthorizationHandler, ControllerActionAccessHandler>();
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

        // SignalR
        services.AddSignalR();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseRequestLocalization(BuildLocalizationOptions());          
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        // Forzo alla pagina principale in caso di pagina non trovata
        app.Use(async (context, next) =>
        {
            await next();
            if (context.Response.StatusCode == 404)
            {
                context.Request.Path = "/Home";
                await next();
            }
        });

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();            
        app.UseStaticFiles();
        app.UseCookiePolicy();
        app.UseAuthentication();

        app.UseSignalR(routes =>
        {
            routes.MapHub<ChatHub>("/chatHub");
        });

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "areas",
                template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
           );
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }

    private RequestLocalizationOptions BuildLocalizationOptions()
    {
        var supportedCultures = new List<CultureInfo>
        {
            new CultureInfo("en-US"),
            new CultureInfo("es-ES"),
            new CultureInfo("de-DE"),
            new CultureInfo("fr-FR"),
            new CultureInfo("ko-KR"),
            new CultureInfo("it-IT")
        };

        var options = new RequestLocalizationOptions
        {
            DefaultRequestCulture = new RequestCulture("it-IT"),
            SupportedCultures = supportedCultures,
            SupportedUICultures = supportedCultures
        };

        return options;
    }

0 个答案:

没有答案