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,645 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

Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

15 Experts available now in Live!

Get 1:1 Help Now