From the course: ASP.NET Core Identity: Authorization Management

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Injecting and using authorization in a view

Injecting and using authorization in a view - ASP.NET Core Tutorial

From the course: ASP.NET Core Identity: Authorization Management

Start my 1-month free trial

Injecting and using authorization in a view

- [Instructor] We have seen so far how to use authorization in c sharp code. So based on the result, we either display the whole view, or not. Now sometimes we might need to hide only a specific part of the view. And to do that, we need to write view-based authorization. To be able to use view-based authorization, we need to inject the authorization service in a razor view. And to inject the authorization service in a razor view, we use the inject directive. So let us go to our project, and make the necessary changes. Before we start changing anything, let us run our application. And we see that we found being authenticated. We can access the Admin, Teacher, and Student dashboard. Let us say when we are in the Admin dashboard and we are not authenticated, we want to display a message to the users, you are not authenticated, and if we are, we want to show them that we are authenticated. For that, let us go to Visual Studio one more time. Go to Solution Explorer, and then inside the…

Contents