Thursday, January 19, 2012

Asp.net class with security feature

To initiate a class if user is logged in with particular role.
For this purpose we need to add attributes on particular class.
eg.

 [PrincipalPermission(SecurityAction.Demand, Authenticated=true)]
 public class Authors
 {
     // Methods
 }

And the below code will prevent the "Authors" class from being instantiated during a request unless the incoming user is in the “Admin” role:


[PrincipalPermission(SecurityAction.Demand, Role="Admin")]
public class Authors
{
    // Methods
}

No comments:

Post a Comment