Implementing authorization

In the first part of the chapter, you saw how to handle user authentication and how to work with user logins. In the next part, you will see how to manage user access, which will allow you to fine-tune who has access to what.

The simplest authorization method is to use the [Authorize] meta decorator, which disables anonymous access completely. Users need to be signed in to be able to access restricted resources in this case.

Let's go and see how to implement it within the Tic-Tac-Toe application:

  1. Add a new method called SecuredPage to the HomeController, and remove anonymous access to it by adding the [Authorize] decorator:
 [Authorize] public async Task<IActionResult> SecuredPage() { return await Task.Run(() ...

Get Learning ASP.NET Core 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.