Authorize attribute is redirecting me to Login action even If I signed in successfully

931 Views Asked by At

I am working on simple login signup in ASP.NET core application. I am using SignInManager class for user to get signin.

enter image description here

When user tries to login the following function will get executed:

enter image description here

When the user enters correct credentials it will redirect to index action in home controller. I have added Authorize attribute for privacy action in home controller:

enter image description here

My question is if I enter correct credentials it is redirecting me to index action in home controller as expected. But if I try to access privacy action in home controller the Authorize attribute is redirecting me to login action in Account controller even if I successfully logged in. What is causing the problem here?

1

There are 1 best solutions below

0
Fei Han On

if I try to access privacy action in home controller the Authorize attribute is redirecting me to login action in Account controller even if I successfully logged in

Please check and make sure you call app.UseAuthentication() and app.UseAuthorization() in correct order shown as below.

app.UseRouting();

            
app.UseAuthentication();
app.UseAuthorization();


app.UseEndpoints(endpoints =>
{
    //...