2
I use ASP.NET and to do the access control by level, I use a filter that checks the level of permission of the user and allows access to view.
[HttpPost]
[AutorizacaoFilterAttribute] //Esse filtro analisa a permissão do usuário
public ActionResult GetEmailAnalisysData()
{
}
But inside the Filter and I need to make one switch
for each view that I add the [AutorizacaoFilterAttribute]
and it ends up being exhausting, plus I’ll forget to add in either.
The question is: It is 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()
{
}
I solved using the inheritance of
AuthorizationFilterAttribute
, I added a variable called Level and now I can pass this value in specific in each View:[AutorizacaoFilterAttribute(Level = 10)]
. Thank you;– Leonardo Bonetti
So you inherited like I said?
– Maniero
Yes ! now instead of using a heap of variables that received the name of the View and as value the necessary level, I just insert the annotation of the filter on top of it passing the level of it, inside the filter I check: Level >= Level (which was passed via attribute),if he allows it, otherwise he sends it to the login page. It made me save about 20 lines (because I made the case for each view of my site).
– Leonardo Bonetti