我关注了the documentation(以及许多博客),以将剃须刀组件添加到剃须刀页面应用程序中。剃须刀页面完美呈现了组件,但随后立即出现“尝试重新连接”的情况,但总是失败。控制台输出说(显然是在localhost上运行):
[2020-07-20T00:22:59.957Z] Information: Normalizing '_blazor' to 'https://localhost:44306/_blazor'.
blazor.server.js:1 [2020-07-20T00:22:59.961Z] Debug: Starting HubConnection.
blazor.server.js:1 [2020-07-20T00:22:59.969Z] Debug: Starting connection with transfer format 'Binary'.
blazor.server.js:1 [2020-07-20T00:22:59.970Z] Debug: Sending negotiation request: https://localhost:44306/_blazor/negotiate?negotiateVersion=1.
blazor.server.js:1 [2020-07-20T00:23:00.145Z] Debug: Selecting transport 'WebSockets'.
blazor.server.js:1 [2020-07-20T00:23:00.174Z] Information: WebSocket connected to wss://localhost:44306/_blazor?id=vuY411dkAsPan4fQrNN3aw.
blazor.server.js:1 [2020-07-20T00:23:00.175Z] Debug: The HttpConnection connected successfully.
blazor.server.js:1 [2020-07-20T00:23:00.175Z] Debug: Sending handshake request.
blazor.server.js:1 [2020-07-20T00:23:00.176Z] Information: Using HubProtocol 'blazorpack'.
blazor.server.js:1 [2020-07-20T00:23:00.182Z] Debug: Server handshake complete.
blazor.server.js:1 [2020-07-20T00:23:00.182Z] Debug: HubConnection connected successfully.
blazor.server.js:1 [2020-07-20T00:23:00.327Z] Information: Close message received from server.
blazor.server.js:1 [2020-07-20T00:23:00.329Z] Debug: HttpConnection.stopConnection(undefined) called while in state Disconnecting.
blazor.server.js:1 [2020-07-20T00:23:00.332Z] Error: Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error.'.
e.log @ blazor.server.js:1
e.stopConnection @ blazor.server.js:1
transport.onclose @ blazor.server.js:1
e.close @ blazor.server.js:1
e.stop @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
a @ blazor.server.js:1
Promise.then (async)
c @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stopInternal @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stop @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
blazor.server.js:1 [2020-07-20T00:23:00.333Z] Debug: HubConnection.connectionClosed(Error: Server returned an error on close: Connection closed with an error.) called while in state Connected.
blazor.server.js:1 Uncaught (in promise) Error: Server returned an error on close: Connection closed with an error.
at e.processIncomingData (blazor.server.js:1)
at e.connection.onreceive (blazor.server.js:1)
at WebSocket.i.onmessage (blazor.server.js:1)
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
Promise.then (async)
c @ blazor.server.js:8
a @ blazor.server.js:8
Promise.then (async)
c @ blazor.server.js:8
(anonymous) @ blazor.server.js:8
r @ blazor.server.js:8
E @ blazor.server.js:8
(anonymous) @ Eol:12448
blazor.server.js:19 [2020-07-20T00:23:03.338Z] Error: TypeError: window.Blazor.reconnect is not a function
e.log @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
r @ blazor.server.js:19
e.attemptPeriodicReconnection @ blazor.server.js:19
e @ blazor.server.js:19
e.onConnectionDown @ blazor.server.js:19
(anonymous) @ blazor.server.js:8
(anonymous) @ blazor.server.js:1
e.completeClose @ blazor.server.js:1
e.connectionClosed @ blazor.server.js:1
connection.onclose @ blazor.server.js:1
e.stopConnection @ blazor.server.js:1
transport.onclose @ blazor.server.js:1
e.close @ blazor.server.js:1
e.stop @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
a @ blazor.server.js:1
Promise.then (async)
c @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stopInternal @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stop @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
blazor.server.js:19 [2020-07-20T00:23:06.346Z] Error: TypeError: window.Blazor.reconnect is not a function
e.log @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
r @ blazor.server.js:19
e.attemptPeriodicReconnection @ blazor.server.js:19
e @ blazor.server.js:19
e.onConnectionDown @ blazor.server.js:19
(anonymous) @ blazor.server.js:8
(anonymous) @ blazor.server.js:1
e.completeClose @ blazor.server.js:1
e.connectionClosed @ blazor.server.js:1
connection.onclose @ blazor.server.js:1
e.stopConnection @ blazor.server.js:1
transport.onclose @ blazor.server.js:1
e.close @ blazor.server.js:1
e.stop @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
a @ blazor.server.js:1
Promise.then (async)
c @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stopInternal @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stop @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
blazor.server.js:19 [2020-07-20T00:23:09.353Z] Error: TypeError: window.Blazor.reconnect is not a function
e.log @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
r @ blazor.server.js:19
e.attemptPeriodicReconnection @ blazor.server.js:19
e @ blazor.server.js:19
e.onConnectionDown @ blazor.server.js:19
(anonymous) @ blazor.server.js:8
(anonymous) @ blazor.server.js:1
e.completeClose @ blazor.server.js:1
e.connectionClosed @ blazor.server.js:1
connection.onclose @ blazor.server.js:1
e.stopConnection @ blazor.server.js:1
transport.onclose @ blazor.server.js:1
e.close @ blazor.server.js:1
e.stop @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
a @ blazor.server.js:1
Promise.then (async)
c @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stopInternal @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stop @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
blazor.server.js:19 [2020-07-20T00:23:12.375Z] Error: TypeError: window.Blazor.reconnect is not a function
e.log @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
r @ blazor.server.js:19
e.attemptPeriodicReconnection @ blazor.server.js:19
e @ blazor.server.js:19
e.onConnectionDown @ blazor.server.js:19
(anonymous) @ blazor.server.js:8
(anonymous) @ blazor.server.js:1
e.completeClose @ blazor.server.js:1
e.connectionClosed @ blazor.server.js:1
connection.onclose @ blazor.server.js:1
e.stopConnection @ blazor.server.js:1
transport.onclose @ blazor.server.js:1
e.close @ blazor.server.js:1
e.stop @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
a @ blazor.server.js:1
Promise.then (async)
c @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stopInternal @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stop @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
blazor.server.js:19 [2020-07-20T00:23:15.390Z] Error: TypeError: window.Blazor.reconnect is not a function
e.log @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
a @ blazor.server.js:19
Promise.then (async)
c @ blazor.server.js:19
(anonymous) @ blazor.server.js:19
r @ blazor.server.js:19
e.attemptPeriodicReconnection @ blazor.server.js:19
e @ blazor.server.js:19
e.onConnectionDown @ blazor.server.js:19
(anonymous) @ blazor.server.js:8
(anonymous) @ blazor.server.js:1
e.completeClose @ blazor.server.js:1
e.connectionClosed @ blazor.server.js:1
connection.onclose @ blazor.server.js:1
e.stopConnection @ blazor.server.js:1
transport.onclose @ blazor.server.js:1
e.close @ blazor.server.js:1
e.stop @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
a @ blazor.server.js:1
Promise.then (async)
c @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stopInternal @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
M @ blazor.server.js:1
e.stop @ blazor.server.js:1
e.processIncomingData @ blazor.server.js:1
connection.onreceive @ blazor.server.js:1
i.onmessage @ blazor.server.js:1
_Layout.cshtml的开头包含<base href="/">
,在<body>
的末尾包含:
<script src="_framework/blazor.server.js" autostart="false"></script>
<script>
Blazor.start({
configureSignalR: function (builder) {
builder.configureLogging(1); // LogLevel.Information
}
});
</script>
我在Pages文件夹的根和中都有_Imports.razor,其中包含
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using MyAppNamespace
Startup.cs在services.AddServerSideBlazor();
中有ConfigureServices
,Configure表示:
.MapRazorPages();
.MapBlazorHub();
.MapFallbackToPage("/_Host");
_Host.cshtml在Pages文件夹中,包含
@page "/blazor"
@{
Layout = "_Layout";
}
<app>
<component type="typeof(App)" render-mode="ServerPrerendered" />
</app>
基于控制台日志,从“索引”页面进行连接可以正常工作,但不适用于使用组件的另一个页面。
我显然缺少一些管道,但我不知道它是什么。我想念什么?
更新:我尝试在“索引”页面中使用blazor组件,那里似乎客户端连接正常,但我看到的是相同的东西:该页面呈现了组件,然后关闭了连接,并且没有尝试重新连接成功。
答案 0 :(得分:0)
您说:_Layout.cshtml包含<href="/">
如果这不是拼写错误,请将其更改为<base href="/">