【发布时间】:2021-06-08 14:42:34
【问题描述】:
我在使用 websockets 的 blazor server 应用程序中遇到问题。
在本地使用应用程序没有问题,但是当我在托管服务器上加载它时,我从浏览器收到这些错误。
应用程序本身可以正常工作,但有时某些用户会收到“正在尝试重新连接到服务器”的消息。
这是我的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 中将其作为 Web 应用程序托管,请确保在 Web 应用程序的配置中启用了“使用 Websockets”选项。否则,整个事情都会崩溃。 - 去过那里。
-
@Dennis1679 我正在向我的主机询问 websockets 设置,因为不幸的是我对服务器几乎没有控制权。
-
@ConnorLow 我的主人说 websockets 是活跃的。还能是什么?
-
您的提供商是否公开了任何调试工具?您可以访问任何服务器日志吗?
标签: c# asp.net-core websocket blazor blazor-server-side