Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
SPSecurity Class
 CatchAccessDeniedException Property

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
SPSecurity.CatchAccessDeniedException Property (Microsoft.SharePoint)
Gets or sets a value indicating whether "access denied" exceptions within page requests are caught and handled by Windows SharePoint Services 3.0.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Visual Basic (Declaration)
Public Shared Property CatchAccessDeniedException As Boolean
Visual Basic (Usage)
Dim value As Boolean

value = SPSecurity.CatchAccessDeniedException

SPSecurity.CatchAccessDeniedException = value
C#
public static bool CatchAccessDeniedException { get; set; }

Property Value

true if the exceptions are handled by Windows SharePoint Services 3.0; otherwise, false. The default is true.

If set to true, access denied exceptions inside page requests are explicitly handled by the platform. For example, when Forms-based authentication is used, anonymous users are redirected to the login page. If the user is already authenticated, he may be redirected to an error message page such as _layouts/AccessDenied.aspx.

If you want to handle access denied exceptions with your own code, you should save the original value in a variable. Set CatchAccessDeniedException to false just before the beginning of your try block. At the end of your code, restore the original value in a finally block, so that other pieces in the system still behave the same way.

This example shows how to save and then restore the value of CatchAccessDeniedException.

bool originalCatchValue = SPSecurity.CatchAccessDeniedException;SPSecurity.CatchAccessDeniedException = false;

try
{
   // details omitted
}
finally
{
   SPSecurity.CatchAccessDeniedException = originalCatchValue;
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Different from SPSite.CatchAccessDeniedException      zhangx   |   Edit   |   Show History
SPSecurity.CatchAccessDeniedException is different from SPSite.CatchAccessDeniedException, SPSite.CatchAccessDeniedException is reserved for internal use and is not intended to be used directly from your code.

bool originalCatchValue = SPSecurity.CatchAccessDeniedException;
SPSecurity.CatchAccessDeniedException = false;
try
{
//Your custom code here
//If a user does not have permission, exception will be thrown
//If CatchAccessDeniedException is true, then the user will be
//redirected to _layouts/AccessDenied.aspx page
}
catch(Exception ex)
{
//Your custom error message can be shown here
}
finally
{
//don't forget to reset the flag to original value
SPSecurity.CatchAccessDeniedException = originalCatchValue;
}
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker