Is there a way to control access to methods to certain roles in .net. Like
class A
{
//should only be called by Admins**
public void Method1() { }
//should only be called by Admins and PM's**
public void Method2() { }
}
I’m using windows authentication only for retrieving user names and nothing more.User roles are maintained in a different application. I think it’s possible through attributes but I’m not really sure how
You can do this as follows:
To do this
Thread.CurrentPrincipalmust be set to a principal that has the required roles. For example, if you enableroleManagerin an ASP.NET application,Thread.CurrentPrincipalwill be set to aRolePrincipalwith roles from your configured RoleProvider. See this MSDN article for more info.