SPSecurity.CatchAccessDeniedException Property

Gets or sets a value indicating whether "access denied" exceptions within page requests are caught and handled by Microsoft SharePoint Foundation 2010.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Public Shared Property CatchAccessDeniedException As Boolean
    Get
    Set
'Usage
Dim value As Boolean

value = SPSecurity.CatchAccessDeniedException

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

Property Value

Type: System.Boolean
true if the exceptions are handled by Microsoft SharePoint Foundation 2010; otherwise, false. The default is true.

Remarks

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.

Examples

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;
}

See Also

Reference

SPSecurity Class

SPSecurity Members

Microsoft.SharePoint Namespace