【问题标题】:Web Socket are not available on signalr core?Web Socket 在信号器核心上不可用?
【发布时间】:2019-03-18 12:32:52
【问题描述】:

我正在研究 asp.net core 2.2 下的信号器核心。我有移动设备和 网络信号器核心客户端,我一直保持跨域连接。我的网络客户端 成功连接到信号器核心,但我的 android 客户端在下面给出异常, "Web 套接字在您的服务器上不可用", 因此,Web 客户端也在使用 Web 套接字传输层,并且处于连接状态。

我的服务器端代码在启动类中

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    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.AddCors(options =>
    {
        options.AddPolicy("CorsPolicy",
            builder => builder.SetIsOriginAllowed((host) => true)/*WithOrigins("https://localhost:44381")*/
            .AllowAnyMethod()
            .AllowAnyHeader()
            .AllowCredentials());
    });
    services.AddSignalR();
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }

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

请回答我,我如何将 android signalr 客户端连接到 signalr 核心服务器?

【问题讨论】:

标签: c# asp.net-core asp.net-core-signalr


【解决方案1】:

您需要在您的服务器上启用WebSockets 支持。

在 Windows Server 2012 或更高版本上启用 WebSockets

  • 使用“管理”菜单中的“添加角色和功能”向导或服务器管理器中的链接。

  • 选择基于角色或基于功能的安装。选择下一步。

  • 选择合适的服务器(默认选择本地服务器)。选择下一步。

  • 在角色树中展开 Web 服务器 (IIS),展开 Web 服务器,然后展开应用程序开发。

  • 选择 WebSocket 协议。选择下一步。

  • 如果不需要其他功能,请选择下一步。

  • 选择安装。

  • 安装完成后,选择关闭退出向导。

【讨论】:

    猜你喜欢
    • 2021-05-10
    • 2019-12-31
    • 2021-02-18
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多