PiotrK
PiotrK

Reputation: 21

Handle Cancel click on Windows authentication

I need to run IdentityServer4 with both Windows Authentication and Basic Authentication. For now, when I trying to login to IdentityServer4 on PC that is not connected to ActiveDirectory, browser shows Login form, where I can fill ActiveDirectory credentials. This is OK.

But now I need to handle click Cancel button on this form, and redirect to local login only HTML form, where I can login with credentials form database (I using .NET Core Authentication). Now when I click Cancel, I'm redirected to 401 error site. Is it possible to handle?

Form where I click "Cancel"

Upvotes: 1

Views: 580

Answers (1)

Souza
Souza

Reputation: 105

I fell in the same situation and in my case I use this middleware extension method

app.UseStatusCodePages(async context =>
{
    if (context.HttpContext.Response.StatusCode == (int)HttpStatusCode.Unauthorized)
    {
        context.HttpContext.Response.ContentType = "text/html";

        await context.HttpContext.Response.WriteAsync(
            string.Format("<script>window.location='../account/Login{0}'</script> ", context.HttpContext.Request.QueryString));
    }
});

Upvotes: 2

Related Questions