Solved

How do I catch and handle a Security Exception thrown when using DECLARATIVE security on a method?

Posted on 2011-03-09
3
1,621 Views
Last Modified: 2013-12-17
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
Comment
Question by:seaero
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Sudhakar Pulivarthi earned 500 total points
ID: 35093410
0
 

Author Comment

by:seaero
ID: 35096055
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
 

Author Closing Comment

by:seaero
ID: 35096070
Didn't actually solve my problem, but provided links that eventually helped me find the answer.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

SHARE your personal details only on a NEED to basis. Take CHARGE and SECURE your IDENTITY. How do I then PROTECT myself and stay in charge of my own Personal details (and) - MY own WAY...
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now