SignalR连接无法协商版本



Iam为几个月前停止工作的项目使用托管的blazor-wasm。但最近我决定改变其中的一些内容,但它已经不起作用了。当我尝试建立SignalR连接时,它会向https://localhost:44322/gameHub/negotiate?negotiateVersion=1地址,它总是返回404代码。我正在使用iis-express来托管这个应用程序。这是我的第一个web和blazor项目,所以我不知道我应该提供哪些信息。我看到了关于这个问题的不同话题,但我甚至不明白,人们在那里提交了什么。

从浏览器调试菜单请求信息

Request URL: https://localhost:44322/gameHub/negotiate?negotiateVersion=1
Request Method: POST
Status Code: 404 
Remote Address: [::1]:44322
Referrer Policy: strict-origin-when-cross-origin
:authority: localhost:44322
:method: POST
:path: /gameHub/negotiate?negotiateVersion=1
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
content-length: 0
origin: https://localhost:44322
referer: https://localhost:44322/10
sec-ch-ua: " Not;A Brand";v="99", "Microsoft Edge";v="91", "Chromium";v="91"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36 Edg/91.0.864.41
x-requested-with: XMLHttpRequest

服务器启动.cs代码

public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
services.AddControllersWithViews();
services.AddRazorPages();
services.AddResponseCompression(opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/octet-stream" });
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseResponseCompression();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebAssemblyDebugging();
}
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.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapHub<GameHub>("/gameHub");
endpoints.MapFallbackToFile("index.html");
});
}

客户端连接代码

HubConnection hubConnection = new HubConnectionBuilder()
.WithUrl(navigationManager.ToAbsoluteUri("/gameHub"))
.Build();
await hubConnection.StartAsync();

我不确定客户在正常工作的时候是否提出了这些要求。我更新了所有的nuget软件包,尝试使用我能找到的所有解决方案,但无济于事。

您需要从服务器项目运行应用程序。默认情况下,visualstudio将客户端项目设置为启动项目,这就是问题所在。

最新更新