R
R
Roman Koff2020-08-07 18:26:07
ASP.NET
Roman Koff, 2020-08-07 18:26:07

Is it possible to get data from an attribute applied to a class in an attribute applied to a class method?

I'm creating an authorization attribute for an ASP.NET MVC controller. At the controller class level, I apply an attribute that checks the user's rights to access the controller. At the level of the controller's action method, I apply an attribute that checks whether the user has the right to perform this action. For example:

[MyAuth("booksmanagers")]
public class BookController
  : Controller
{
  [MyAuthRight("booksmanagers", "create")]
  public ActionResult Create()
  {
    return View();
  }
}

The MyAuth attribute checks if the current user is a member of the "booksmanagers" role.
The MyAuthRight attribute checks if the current user is a member of the "booksmanagers" role with the "create" right.

Is it possible, within the class, not to explicitly specify the role parameter in the MyAuthRight attribute, but to get it programmatically from the parent attribute?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2020-08-08
@yarosroman

And what is the built-in authorization not satisfied with? Policies can be flexibly configured.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question