You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And my AuthenticationHttpMessageHandler is simply opens a dialog
public class AuthenticationHttpMessageHandler : DelegatingHandler
{
private readonly LoginModalService _loginModalService;
public AuthenticationHttpMessageHandler(LoginModalService loginModalService)
{
_loginModalService = loginModalService;
}
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
var response = await base.SendAsync(request, cancellationToken);
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
await _loginModalService.ShowLoginModal();
}
return response;
}
}
public class LoginModalService(IDialogService dialogService)
{
private readonly IDialogService _dialogService = dialogService;
public event Action? OnLogin;
public async Task ShowLoginModal()
{
var dialog = await _dialogService.ShowAsync<TestModal>();
var result = await dialog.Result;
if (result?.Canceled == false)
{
OnLogin?.Invoke();
}
}
}
If I try to Inject IDialogService and Show a dialog on OnAfterRenderAsync method it simply works, but if I try to call an API and it invoke the ShowAsync in LoginModalService witch is calling from AuthenticationHttpMessageHandler it will not working.
Any workaround or fix?
My Project is .NET 8.0 and I'm using default Mudblazor Server template for my app.
dotnet new mudblazor --interactivity Server --name MyApplication --all-interactive
The text was updated successfully, but these errors were encountered:
Hi. This is expected since you cannot open such things from a non-UI thread. The same applies not only to Blazor but also to WPF and WinForms (an example would be if you try to call the Show method on a window).
Any workaround or fix?
You would need a long-lived Blazor component, for example, one that sits in the root of MainLayout and listens for dialog requests, possibly using a pub/sub pattern. Once it gets a notification to open a specific dialog, it simply calls _dialogService.ShowAsync inside an InvokeAsync (in other words, it queues the action on the UI thread). This is why a Blazor component is required, as only it has access to Dispatcher.InvokeAsync. Unlike WPF, there is no Application.Current.Dispatcher that can be accessed from anywhere.
Hi everyone,
I want to handle 401 status code globally to open a Dialog to login user.
So I tried to Add related services into my program
And my AuthenticationHttpMessageHandler is simply opens a dialog
If I try to Inject IDialogService and Show a dialog on
OnAfterRenderAsync
method it simply works, but if I try to call an API and it invoke the ShowAsync inLoginModalService
witch is calling fromAuthenticationHttpMessageHandler
it will not working.Any workaround or fix?
My Project is .NET 8.0 and I'm using default Mudblazor Server template for my app.
dotnet new mudblazor --interactivity Server --name MyApplication --all-interactive
The text was updated successfully, but these errors were encountered: