seaero
asked on
How do I catch and handle a Security Exception thrown when using DECLARATIVE security on a method?
I have a method with Declarative security defined as such:
Whenever I click on the button which executes the MyButton_Click() method, a SecurityException is thrown (as expected) because the user does not have the proper permissions to access the method. My problem is that I cannot seem to catch the SecurityException that is being thrown in order to handle it gracefully.
I've tried adding try/catch blocks within the method as well as in the constructor of the WPF Window, and in the application Main() method. It seems that no matter where I put the try/catch, I cannot catch the SecurityException. Any clues?
[PrincipalPermissionAttribute(SecurityAction.Demand, Name="test", Role="Administrator")]
private void MyButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
// do something
}
Whenever I click on the button which executes the MyButton_Click() method, a SecurityException is thrown (as expected) because the user does not have the proper permissions to access the method. My problem is that I cannot seem to catch the SecurityException that is being thrown in order to handle it gracefully.
I've tried adding try/catch blocks within the method as well as in the constructor of the WPF Window, and in the application Main() method. It seems that no matter where I put the try/catch, I cannot catch the SecurityException. Any clues?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Didn't actually solve my problem, but provided links that eventually helped me find the answer.
ASKER
However, the links you provided helped me find what I was looking for. I basically ended up using a Global Exception Handler at the app level with DispatcherUnhandledExcepti
I will give you the points for attempting to answer. Thanks!