New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(BlazorServer) each navigation to external logs 2 errors a minute later #45267
Comments
Thanks for contacting us. We're moving this issue to the |
Having rolled out our software with update net6->net7 our SEQ counter for (important) circuit crashes now increased from 20-40 per day to 1600-2000 per day. One more callstack seems to be new, too:
|
I am having the same issue, everything was working just fine. After shut down and restart then it started. Microsoft Edge will not even display anything and the error message comes to the console. Firefox displays the home but when you click the Login button then after a minute or so the error will show in console. Below is the error. info: Microsoft.Hosting.Lifetime[14] |
Observations: Microsoft Edge is not able to display the home page at all. Firefox is able to display the home page, you are able to click login and fill in the form but when you click the blue login button, a few minutes later it logs the above errors. Visual Studio Community edition version 17.4.2 I did windows update yesterday. That is the only thing I did that from then on it started given the error above. I hope the updated information helps. |
Also running into a simalar exception with MircosoftIdentity
|
Upon further investigation, I realized it was coming from the OnPostAsync method. I found out that Microsoft SQL server had stopped after windows update. Restarting SQL server in the services applet stopped the error and everything was okay. If in your appsettings.json file you use IP Address and you move to another subnet, you may experience similar frustration. Correction to the new IP Address will resolve the issue. But strangely when I put the whole code block in a try catch nothing happened. It couldn't move past the following code which is the problematic code when SQL Server is offline and you don't know it's offline:
` public async Task OnPostAsync(string returnUrl = null)
` |
@springy76 @mkArtakMSFT any updates or known workarounds for this one? |
i have the same issue. I check if the user is authenticated, if not i redirect to the login page. My App.razor looks like this. <CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (!IsAuthenticated())
{
<h1>Hi,</h1>
<p>You need to login</p>
<a href="login?redirectUri=@NavigationManager.Uri">Login now</a>
}
else
{
<h1>Hi,</h1>
<p>You have no access rights</p>
<p>Contact an administrator</p>
}
</NotAuthorized>
<Authorizing>
<p>Loading...</p>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>404 - Not Found</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
@code {
private bool IsAuthenticated()
{
var authState = AuthenticationStateProvider.GetAuthenticationStateAsync().Result;
var user = authState.User;
if (user.Identity!.IsAuthenticated)
{
return true;
}
else
{
try {
NavigationManager.NavigateTo($"login?redirectUri={NavigationManager.Uri}", true, true);
}
catch { }
return false;
}
}
} Error
It's a Blazor Server Application, .NET 7 |
@Schtailian just a side note regarding your code snippet: Do not use the
|
@springy76 thanks, that looks way better. Just for future readers, the awaited state is part of the It should look like this: <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" Context="authState">
<NotAuthorized>
@if (!IsAuthenticated(authState)) |
@Schtailian now it looks wrong to me - to my knowledge Just for future readers, the state part definitely is part of the |
@springy76 Sorry, yea you totally write. I was to impatient with intellisense 🙉 <NotAuthorized Context="authState">
@if (!IsAuthenticated(authState)) |
Hi,
I still get these. I think they might happen with this component https://github.com/Blazored/Toast, but i haven't tried so far. @springy76 do you use anything similar? |
Thanks for contacting us. We're moving this issue to the |
Leaving this comment here for a fix that worked for me. NavManager.NavigateTo(returnUrl != null ? $"/middleware-login?key={key}&returnUrl={returnUrl}" : $"/middleware-login?key={key}", true, true); After replacing it with this: @inject IJSRuntime JSRuntime
...
await JSRuntime.InvokeVoidAsync("window.location.assign", returnUrl != null ? $"/middleware-login?key={key}&returnUrl={returnUrl}" : $"/middleware-login?key={key}"); I stopped getting those exceptions from NavigationManager. Hope this is helpful to others! EDIT: Also, I noticed that the aforementioned exceptions appear if you try to navigate to a page that doesn't exist. |
@Schtailian no, it's just the unchanged template created by and still the same with net8 + Blazor WebApp + Individual Auth .. multiple errors in console after just some simple clicks |
yep, still the same with .net 8 also for me. @mkArtakMSFT is there anything we can do, to prevent this? |
Thanks for contacting us. We're moving this issue to the |
@HoofedEar Thanks, your solution with JSRuntime works! :) For issuetracker: I noticed that this bug happens only in Firefox browser. No errors with Chromium based browsers. |
…nute later (#53297) Backport of #53271 to release/8.0 /cc @javiercn # [Blazor] each navigation to external logs 2 errors a minute later Capture an exception and log a message when navigation fails because the session has ended. ## Description - The user clicks the link to the target URL. - That link is intercepted in the JavaScript. - .NET is called to determine if navigation to the URL needs to be prevented. - It is determined that there is no need to prevent navigation and "navigateTo" is called via JS interop in NavigationManager.ts. - The URL is determined to be external by "navigateTo" and the location is set to the new URL. - The unload event in the browser is automatically triggered, which in turn triggers the call to _disconnect. - As a result, the promise to "navigateTo" never completes (the page gets unloaded before that) and the associated task in .NET ends up getting cancelled with a timeout. Fixes #45267 ## Customer Impact Customers see a large number of errors in their logs when their sites contain links to external sites, which in turn can trigger alerts in their incident monitoring systems. ## Regression? - [ ] Yes - [X] No ## Risk - [ ] High - [ ] Medium - [X] Low The scenario in which the issue happens is well defined and the fix is simple. ## Verification - [X] Manual (required) - [ ] Automated ![image](https://github.com/dotnet/aspnetcore/assets/6995051/a61a9898-771a-414c-a83c-7836bf88697c) ## Packaging changes reviewed? - [ ] Yes - [ ] No - [X] N/A ---- ## When servicing release/2.1 - [ ] Make necessary changes in eng/PatchConfig.props --------- Co-authored-by: jacalvar <jacalvar@microsoft.com>
Why is this issue closed? I updated to .NET 8.0.3 and still these Exceptions occure |
also still occurs for me. |
also still occurs for me. Message Navigation failed when changing the location to "/pages/authentication/login" Exception System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args) at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args) at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.<>c__DisplayClass13_0.<g__PerformNavigationAsync|0>d.MoveNext() |
.Net 8.0.202 After the Token expires, perform a jump to report an error |
It still occurs for us as well, albeit at a significantly reduced rate. Could you take another look @mkArtakMSFT ? Thanks =) |
I am also dealing with this, and have come to find this is a known issue? I'm not sure I'm a fan of the Js workaround... 04/15/2024 14:11:42 Navigation failed when changing the location to "https://localhost:xxxx/MicrosoftIdentity/Account/SignIn" 04/15/2024 14:11:42 Unhandled exception in circuit '"xxxxxxxxx"'. |
Still occurs for me also. What's odd is that I seem to only get this when on iOS & iPadOS. |
Is there an existing issue for this?
Describe the bug
Each time you leave the blazor circuit a minute later two exceptions are logged.
Expected Behavior
zero errors in log when no one does wrong things.
Steps To Reproduce
Run original sample created by
dotnet.exe new blazorserver --name BlazorServerTemplate --output . -f net7.0 --auth Individual --use-program-main
On top right click on "Login" which is
<a href="Identity/Account/Login">Log in</a>
inLoginDisplay.razor
.Wait a minute (or maybe 2) then 2 errors are logged to console (or external logging apps like SEQ):
Exceptions (if any)
TaskCancelledException
.NET Version
7.0.0
The text was updated successfully, but these errors were encountered: