.NET security: how to check if a method is allowed to execute under current user's perrmissions

Posted by Gart on Stack Overflow See other posts from Stack Overflow or by Gart
Published on 2010-05-05T11:08:39Z Indexed on 2010/05/05 12:48 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

Given an ASP.NET MVC Controller class declaration:

public class ItemController : Controller
{
    public ActionResult Index()
    {
       // ...
    }

    public ActionResult Details()
    {
       // ...
    }

    [Authorize(Roles="Admin, Editor")]
    public ActionResult Edit()
    {
       // ...
    } 

    [Authorized(Roles="Admin")]
    public ActionResult Delete()
    {
      // ..
    }
}

I need to reflect a list of methods in this class which may be invoked with the current user's permissions.

The [Authorized] attribute is specific to ASP.NET MVC, and this is only an example. I would prefer a universal solution for this problem which works for any .NET class.

Please share some ideas of what could be done in this case.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about security