gpt4 book ai didi

c# - Blazor 服务器 WebSocket 连接失败 : There was an error with the transport

转载 作者:行者123 更新时间:2023-12-04 17:18:19 25 4
gpt4 key购买 nike

我在 blazor server 中有问题申请与 websockets .
在本地使用该应用程序我没有问题,但是当我将它加载到托管服务器上时,我从浏览器收到这些错误。
应用程序本身可以正常工作,但有时一些用户会收到消息“正在尝试重新连接到服务器”。
websocket error
这是我的 Startup.cs

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

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
// ******
// BLAZOR COOKIE Auth Code (begin)
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => options.ExpireTimeSpan = TimeSpan.FromDays(1));

// BLAZOR COOKIE Auth Code (end)
// ******

services.AddMudServices();

services.AddRazorPages();
services.AddServerSideBlazor();

services.AddHttpContextAccessor();


// ******
// BLAZOR COOKIE Auth Code (begin)
// HttpContextAccessor
services.AddHttpContextAccessor();
services.AddScoped<HttpContextAccessor>();
services.AddHttpClient();
services.AddScoped<HttpClient>();
// BLAZOR COOKIE Auth Code (end)
// ******
}

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

app.UseHttpsRedirection();

app.UseRouting();

// ******
// BLAZOR COOKIE Auth Code (begin)
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
// BLAZOR COOKIE Auth Code (end)
// ******

app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
可能是什么问题呢 ?

最佳答案

我得到了同样的错误。我没有打开 Azure 应用服务的 ARR 关联。
打开它解决了这个问题。
看:
https://docs.microsoft.com/en-us/aspnet/core/signalr/publish-to-azure-web-app?view=aspnetcore-5.0#configure-the-app-in-azure-app-service

关于c# - Blazor 服务器 WebSocket 连接失败 : There was an error with the transport,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67889297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com