Implement object-level security with attributes in ASP.NET MVC

Is it possible to implement object level protection with ActionFilterAttribute?

I read Branislav Abadzhimarinov responded to Get permission from an authorized attribute? and began to think about creating a AuthorizeAttribute-shaped action filter to implement object-level protection.

Suppose I had to call it ObjectAuthorizeAttributewith the intended use:

[ObjectAuthorize]
public ActionResult Edit(int id)
{
    //...

What would be the easiest way to access the id value in OnActionExecuting?

Is something like this already available?

+3
source share
2 answers

AuthorizeAttribute , RouteData, AuthorizationContext. , , AuthorizeAttribute, ActionFilterAttribute.

var id = filterContext.RouteData.Values["id"];
+2
var id = filterContext.HttpContext.Request["id"];
+1

Source: https://habr.com/ru/post/1787306/


All Articles