Questions about AuthorizationRules.AllowExecute

Questions about AuthorizationRules.AllowExecute

Old forum URL: forums.lhotka.net/forums/t/5518.aspx


FrankM posted on Thursday, October 02, 2008

  1. Does this syntax only work for instance method? If yes, what's the suggested way to if I want to do the similar thing to protect static method?
  2. I have to call CanExecuteMethod(methodName) in my instance method to take advantage of the role setting set by AllowExecute() earlier. Is this kind of unnecessary?
  3. What's the reason the old CanExecuteMethod() (no methodName in parms) become obsolete?
Thanks.

JoeFallon1 replied on Thursday, October 02, 2008

For #3 - it is probably the same reason that the no parameter version of CanReadProperty was made obsolete. They relied on walking a stack trace to locate the property name for you. It turns out that is unreliable. So you have to provide the name in your code.

Joe

 

FrankM replied on Thursday, October 02, 2008

Thanks Joe, that means the code shown in another post is not stable?
string methodName = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name.Substring(4);

sergeyb replied on Thursday, October 02, 2008

Correct, this code is not reliable.  It may work most of the time, but not 100 % of the time.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: FrankM [mailto:cslanet@lhotka.net]
Sent: Thursday, October 02, 2008 4:38 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] Questions about AuthorizationRules.AllowExecute

 

Thanks Joe, that means the code shown in another post is not stable?

string methodName = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name.Substring(4);



Copyright (c) Marimer LLC