From the course: ASP.NET Core: Token-Based Authentication
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Adding role authentication to a controller - ASP.NET Core Tutorial
From the course: ASP.NET Core: Token-Based Authentication
Adding role authentication to a controller
- [Instructor] So far, we have just added the authorized attribute in the home controller, which required all the users to be authenticated. And anyone, regardless of their role, could access that controller. On this part, you'll learn how to add roles to the authorized attribute, so only the defined roles can access the controller. So, for example, the student controller is going to be accessed just by the students and the manager controller just by the users with the manager role. For that, let us go to Visual Studio. In Visual Studio, I'll go to the Solution Explorer, and then you're going to go to the Controllers. And in Controllers, I'll open the management controller and the student controller. I the student controller I'll add the authorized attributes, so authorize then import the namespace, which is the AspNetCore.Authorization and then here, define the role. So roles is equal to the user roles dot, and then we…