C# 网站发布后未找到信号集线器
我有一个ASP.NETCore3.1WebApp,其中包括Razor页面、Api控制器和信号器中心。我的C# 网站发布后未找到信号集线器,c#,asp.net-core,signalr,asp.net-core-signalr,C#,Asp.net Core,Signalr,Asp.net Core Signalr,我有一个ASP.NETCore3.1WebApp,其中包括Razor页面、Api控制器和信号器中心。我的Startup.cs如下所示: public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddRazorPages(); services.AddSignalR(options => { options.
Startup.cs
如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddRazorPages();
services.AddSignalR(options =>
{
options.EnableDetailedErrors = true;
});
services.AddMvc();
services.AddSingleton<HubManager>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDeveloperExceptionPage();
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapHub<MainHub>("/MainHub");
});
}
const connection = new signalR.HubConnectionBuilder()
.withUrl("/MainHub", {
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets
})
.configureLogging(signalR.LogLevel.Information)
.withAutomaticReconnect()
.build();
async function start() {
try {
await connection.start();
console.log("connected");
} catch (err) {
console.log(err);
setTimeout(() => start(), 5000);
}
};
connection.onclose(async () => {
await start();
});
start();
然后我发布webapp并导航到使用signar(使用Chrome)的页面。但当我检查控制台时,我看到SignalR大约每1s轮询一次,并且此错误持续显示:
signal.js:4709 WebSocket连接到'wss://myurl/MainHub'失败:WebSocket握手期间出错:意外响应代码:404
js:61错误:传输出错。
在WebSocket.WebSocket.onerror(signal.js:4728)
- https://myurl/MyWebApp/Home/MyPage
- https://myurl/MyWebApp/js/signalr/dist/browser/signalr.js
- wss://myurl/MainHub
const connection = new signalR.HubConnectionBuilder()
.withUrl("/MyWebApp/MainHub", {
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets
})
.configureLogging(signalR.LogLevel.Information)
.withAutomaticReconnect()
.build();
我想和你们确认一下这些信息:1)razor和api部分的路由可以在服务器上工作吗?2) 如果不限制客户端仅使用
WebSockets
传输,它是否有效?3) 服务器日志中有什么有用的信息吗?@FeiHan 1)api工作的路由,对于razor仍然未知,因为我仍在构建应用程序2)客户端仅限于WebSocket,如上所示3)iis服务器日志或信号器?我现在收到此错误:WebSocket连接到'wss://myUrl/MyWebApp/MainHub?id=rjBcaMyToBn0GsQ6j2ZXQA'失败:WebSocket握手期间出错:意外响应代码:200您可以尝试使用配置它其他传输(如LongPolling)并检查它是否可以工作。
const connection = new signalR.HubConnectionBuilder()
.withUrl("/MyWebApp/MainHub", {
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets
})
.configureLogging(signalR.LogLevel.Information)
.withAutomaticReconnect()
.build();