[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1891
  • Last Modified:

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:

[PrincipalPermissionAttribute(SecurityAction.Demand, Name="test", Role="Administrator")]
private void MyButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
   // do something
}

Open in new window


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?
0
seaero
Asked:
seaero
  • 2
1 Solution
 
seaeroAuthor Commented:
Since I am not using WCF, I couldn't implement the IErrorhandler in my WPF application.

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 DispatcherUnhandledExceptionEventHandler as outlined here: http://www.devx.com/tips/Tip/42431

I will give you the points for attempting to answer. Thanks!
0
 
seaeroAuthor Commented:
Didn't actually solve my problem, but provided links that eventually helped me find the answer.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now