It would have to be slightly different. It would have to be something like:
[AuthorizationRu le("SomeRuleNam e")]
public void MethodRequiring Authorization()
{
if (Principal.Auth orize())
{
}
}
Principal.Autho rize 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*********@ro ckcreekglobal.c om> wrote in message
news:%2******** ********@TK2MSF TNGP12.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:
[AuthorizationRu le( "SomeRuleNa me" )]
public void MethodRequiring Authorization()
{
... some code that requires authorization
}
But then have this code changed at compile time to something like:
public void MethodRequiring Authorization()
{
if( Principal.Autho rize( "SomeRuleNa me" ) )
{
... 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//