It would have to be slightly different. It would have to be something like:
[AuthorizationRule("SomeRuleName")]
public void MethodRequiringAuthorization()
{
if (Principal.Authorize())
{
}
}
Principal.Authorize could then determine the attribute by walking the stack
and then using reflection to get the attribute from the calling method. But
at that point, you may as well pass it as a parameter as make it an
attribute. It would be faster than the stack-walk and reflection.
What it seems you really want to do is have some sort of trigger that the
method is called so that you can do the authorization when the method is
called. Unfortunately, there isn't a way, that I know of, to do that.
Pete
"Chris Newby" <ch*********@rockcreekglobal.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I am trying to implment some business level user authorization in my
current .net 1.1 app. In C#, I would like to do something like:
[AuthorizationRule( "SomeRuleName" )]
public void MethodRequiringAuthorization()
{
... some code that requires authorization
}
But then have this code changed at compile time to something like:
public void MethodRequiringAuthorization()
{
if( Principal.Authorize( "SomeRuleName" ) )
{
... some code that requires authorization
}
}
Is there a way to do this? If not, is there some other way I can
accomplish the desired effect which is to decorate code with authorization
rules instead having to actually code it?
TIA//