Skip to content

Blazor WASM: logout when got 401, should i expect logout to be run when call #53777

Answered by ghostinside
ghostinside asked this question in Q&A
Discussion options

You must be logged in to vote

finally did through handler

`public class CustomDelegatingHandler(NavigationManager navm, IConfiguration config) : DelegatingHandler
{
protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include);
var response = await base.SendAsync(request, cancellationToken);
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
Console.WriteLine("CustomDelegatingHandler | SendAsync | HttpStatusCode.Unauthorized");

        navm.NavigateTo(config["Identity:LoginPath"]);
    }
    return response;
}

}`

hope if i create control & place it to page & inject auth state service to the cont…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ghostinside
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant