SPC010212: Do not set SPSite.CatchAccessDeniedException property

Property SPSite.CatchAccessDeniedException is reserved for internal use. Use the SPSecurity.CatchAccessDeniedException property instead to specify whether SharePoint Foundation traps and handles "Access Denied" exceptions.

TypeName: DoNotCallSPSiteCatchAccessDeniedException
CheckId: SPC010212
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

Use SPSecurity.CatchAccessDeniedException instead of using SPSite.CatchAccessDeniedException. Mircosoft warns to use members which are reserved for internal use only because your code could break in the next hotfix or service pack. See sample below:

Bad Example:

using (SPSite spSite = new SPSite("http://url/"))
{
  bool originalCatchValue = spSite.CatchAccessDeniedException;  
  spSite.CatchAccessDeniedException = false;
  try
  {
      // Perform the task here
  }
  finally
  {
      spSite.CatchAccessDeniedException = originalCatchValue;
  }
}
Good Example:
using (SPSite spSite = new SPSite("http://url/"))
{
  bool originalCatchValue = SPSecurity.CatchAccessDeniedException;
  SPSecurity.CatchAccessDeniedException = false;
  try
  {
      // Perform the task here
  }
  finally
  {
      SPSecurity.CatchAccessDeniedException = originalCatchValue;
  }
}

Links

comments powered by Disqus