[Please note this question is about DotNet Core 1.1]
I have a controller method in my ItemsController class attributed as follows to restrict the ability to access the method to users in an administrator group:
[Authorize(Roles = @"MYDOMAIN\ThisApplicationAdmins")]
[HttpDelete("/items/{itemsName}")]
public ActionResult DeleteItem(string itemName)
{
// Dangerous code here.
}
This works correctly.
I would, additionally, like to remove the red X in the application that triggers this controller method for users who cannot access the method. I know that I could check to see whether the user is in the correct AD group but this requires me to duplicate my authorization logic and exposes me to the possibility that I will update the attribute, but not the user interface check.
Does there exist a way to query ASP DotNet core to ask "Is user X authorized to access method ItemsController.DeleteItem()?" and have that question answered by the same middleware that is responsible for processing the attribute?
Yes,U can check in middle level between UI and controller that particular user has access to requested Controller or not.
/We need to add somewhere in ur View below async method/
Implemntation of the method:-