question

6666666 avatar image
0 Votes"
6666666 asked yogyogi commented

Is there a light authentication in asp.net core?

There is a tag

     [Authorize]
     public class IndexModel : PageModel
     {
 }

The [Authorize] I can add to the page class then I can not view the page if it is not authenticated.

How to add authentication ? that I can view the page?

I do not want to use Identity server.

and do not want to use ASP.NET Core Identity since it will generate tables .

I just want to verify the username and password and write authentication information to view the page.

thank you

dotnet-aspnet-core-razor
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I do as it say. and add SignInAsync();

But the page which is taged with [Authorize] will auto redirect to login.

It is not logged. why?

0 Votes 0 ·

Hi @65841535 ,Can you provide your startup class?

0 Votes 0 ·

You can use cookie authentication if you do not want to use Identity.

0 Votes 0 ·

1 Answer

YinqiuYao-MSFT avatar image
0 Votes"
YinqiuYao-MSFT answered

Hi @65841535 ,

You can see the details in this article.

And remember the middleware is

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

They are indispensable and the order is also very important.


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.