【问题标题】:Problem with SignalR when hosting Serverside Blazor App托管服务器端 Blazor 应用程序时 SignalR 出现问题
【发布时间】:2019-11-26 11:19:00
【问题描述】:

当我在 Visual Studio 代码中的开发机器上运行我的服务器端 Blazor 应用程序时,一切正常。 但是在使用 Apache2 部署到 Linux 服务器后,客户端到服务器的 WSS:// SignalR 连接出现问题。

https://shop.gastroblitz.de/的运行根页面 导致控制台错误:

Firefox kann keine Verbindung zu dem Server 位于 wss://shop.gastroblitz.de/_blazor?id=P1LOmrVSgCD4fAWd9lAhHQ aufbauen。 blazor.server.js:1:30021 [2019-07-17T14:58:20.948Z] 错误:无法启动传输“WebSockets”:null

我有重定向的反向代理配置 - https:// 在服务器中调用http://localhost:5000(托管 dotnet 服务的地方) - wss:// 调用 ws://

似乎在 https:// 上可以正常工作,但我无法使用 wss:// 启动的 SignalR 事情并导致上层错误...

使用 Visual Studio 最新预览版和 dotnetcore-preview6。

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;

        SqlHub.ConnectionString = Configuration["ConnectionString"];
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddRazorPages();
        services.AddServerSideBlazor();
        services.AddScoped<OrderState>();
        services.AddScoped<StoreData>();
        services.AddScoped<BasketManager>();
        services.AddBlazoredModal();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        //app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
        });
    }

我希望将整个 Blazor 应用程序放在服务器上,就像它在我的 Visual Studio 环境中运行一样。如果有人对 SSL / wss 和所有配置内容有有用的提示,那就太好了……谢谢!

【问题讨论】:

  • here 应用程序的控制台结果ibb.co/DMmk8xP
  • 在 Azure 上,您必须打开 WebSockets。我建议你在 Apache 中寻找类似的设置。

标签: websocket server hosting blazor


【解决方案1】:

您需要在服务器上启用 websockets 才能正常工作。

【讨论】:

  • 好的,但这是服务器端 Blazor 应用程序 - 因此除了运行端口 5000 + 5001 的此 dll 之外没有其他服务器。外部请求通过反向代理到达它。如何在服务器(Blazor 应用程序)中启用 WebSocket?
猜你喜欢
  • 2020-09-26
  • 2023-01-19
  • 1970-01-01
  • 2021-10-03
  • 2021-03-18
  • 1970-01-01
  • 2021-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多