How can I implement a attribute like "PrincipalPermission"


i attribute "principalpermission", because when call method mymethod, check permission first. found when check permission failed, throws exception.

my question how can implement attribute this: when check permission failed, not step method "mymethod", instead of throw exception?

 

code snippet

        [principalpermission(securityaction.demand, role = "user")]
        private void mymethod()
        {
            string ss = "abc";
        }

 

 

(offcourse first create concrete permission(set) , demand don't see how useful)

if you're talking principalpermission can following:

code snippet

if (thread.currentprincipal.isinrole("user"))
{
 mymethod();
}


but following, , more generic solution use try/catch block:

code snippet

try
{
 mymethod();
}
catch (securityexception sex)
{

}




to answer question: afaik it's impossible without exceptions, because that's way failures meet required permissions signalled back...


.NET Framework  >  Common Language Runtime Internals and Architecture



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'