tags:

views:

251

answers:

2

I have a WCF service that has methods with the PrincipalPermission attribute on them. When a user that does not have the appropriate permissions tries to access those methods the attribute throws a SecurityException but since the exception is thrown in the attribute it's not possible to put try..chatch around the call.

I have tried using the ExceptionShielding attribute from the Enterprise Library with a logging handler but it does not write any logs. I even tried writing a WCF Behavior extension to try and catch the exception but the extension could not call the exception handling block properly.

Does anyone have a good idea of how to achieve this.

+1  A: 

Two suggestions for you:

1) Switch to using PrincipalPermission.Demand() instead of the attribute.

2) Take a look here in the comments (#5 I think). Ignore the link provided to the code there - code is here on Google Code. Nick Berardi has created an ExceptionHandlerAttribute to turn specified exceptions into web responses. Now this doesn't quite match your scenario, but his class must be catching the Exception thrown by the PrincipalPermission attribute, so maybe you can make use of the same principal.

Xiaofu
This is exactly what I needed, thank you very much :-)
Kjartan Þór Kjartansson
A: 

Suggestion 2) is only usable from MVC

Seeker