我创建了 Blazor 服务器 Web 应用程序,并将其部署在 Azure 应用服务上,并在Network
选项卡我看到很多请求https://mywebsites0123.azurewebsites.net/_blazor?id=3OO-T6L4Bu9bMRF8QAo_5Q&_=166722
并使应用程序不稳定。
在本地主机(调试和发布)上,我找不到任何请求,并且应用程序运行顺利。
我读了这个C# Blazor 服务器 - 为什么有这么多 _blazor 请求和如此多的内存消耗?但找不到解决方案。
启动页面如下所示:
ConfigureServices(IServiceCollection services)
services.AddRazorPages();
services.AddServerSideBlazor().AddMicrosoftIdentityConsentHandler();
services.AddSignalR(e =>
{
e.MaximumReceiveMessageSize = 2000 * 1024;
});
// Radzen init
services.AddScoped<DialogService>();
services.AddScoped<TooltipService>();
services.AddScoped<NotificationService>();
services.AddMemoryCache();
var apiScope = Configuration["Authentication:ApiScope"];
services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "Authentication:AzureAd")
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { apiScope })
.AddInMemoryTokenCaches();
services.AddControllersWithViews().AddMicrosoftIdentityUI();
services.AddAuthorization();
and
Configure(IApplicationBuilder app, IWebHostEnvironment env)
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
I receive alot of requests:
几秒钟后:
然后请求数量继续增加。不知道当应用程序托管在 Azure 应用程序服务上时为什么会发生这种情况。
有什么要寻找的提示吗?
解决方案:
在 Azure AppService 上启用 WebSockets(默认情况下为关闭)描述:https://learn.microsoft.com/en-us/aspnet/core/signalr/publish-to-azure-web-app?view=aspnetcore-6.0#configure-the-app-in-azure-app-service