Is it possible to insert parameters in the filters attributes?

2

I use ASP.NET and to do access control by level, I use a filter that checks the user's permission level and allows access to view .

[HttpPost]
[AutorizacaoFilterAttribute] //Esse filtro analisa a permissão do usuário
public ActionResult GetEmailAnalisysData()
{

}

But inside the Filter, I need to make a switch for every view I add [AutorizacaoFilterAttribute] and this ends up being tiresome, outside that I'll forget about add on one or the other.

The question is: Is it possible to pass parameters through filter ? example:

[HttpPost]
[AutorizacaoFilterAttribute(1)] //1 significa o nível necessário para esse filter, assim eu me livro de precisar fazer um switch comparando o nome de cada view
public ActionResult GetEmailAnalisysData()
{

}
    
asked by anonymous 08.05.2018 / 17:17

1 answer

3

In this case your can do as you want, but if you use #

You can create your inheriting AuthorizationFilterAttribute , there you can add a constructor with the parameter you want. But the framework will not respect this, it will be necessary to create the control logic, perhaps creating a AuthorizationFilterAttribute itself as well. Even because this level would have to be sent somehow to compare with this argument. I do not know how to do it without the attribute.

Another possibility is to have different actions for each level.

    
08.05.2018 / 17:25