Reputation: 21
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?
Upvotes: 1
Views: 580
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