Reputation: 604
I am using ASP.NET Core MVC. In my project I use Ajax in order to get some JSON data from an action on my controller. It requests data from the database, then return it as json. It works well.
I want to use role-based authentication in my ASP.NET Core MVC project.
This is my question: if I use a controller action restriction by something like [Authorize(Roles = "Admin")]
, will it allow anyone whose role is "Admin" to call this method? (I mean will it work without any other trouble just by logging in as Admin)
And will it disable accessing those data when the role is not "Admin"`?
I have not still add Identification to my new project and I'm new to using Ajax.
Upvotes: 0
Views: 141
Reputation: 604
I have just tested it and it does as desired. It return 401 Unauthorized
status code when the user is not authorized and 200 OK
success status response code. Thanks guys for your responses.
Upvotes: 1