M
M
mindgrow2021-09-02 11:19:13
ASP.NET
mindgrow, 2021-09-02 11:19:13

How to disable redirect to Identity/Account/Login from CustomAuthorizationAttribute?

Tell me, I
use asp.net core with a self-written authorization system (not identity)
, I implemented CustomAuthorizationAttribute,
if successful, a redirect to Identity/Account/Login
Identity occurs
.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2021-09-02
@sarapinit

services.ConfigureApplicationCookie(options =>
{
    options.Events.OnRedirectToLogin = context =>
    {
        context.Response.StatusCode = 401;
        return Task.CompletedTask;
    };
});

services.AddAuthentication(options => options.DefaultScheme = "Cookies").AddCookie("Cookies", "Cookies", options => {
    options.Events.OnRedirectToAccessDenied = context => 
    {
        context.Response.StatusCode = 403;
        return Task.CompletedTask;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question