Saturday, January 30, 2010

Asp.Net Alternative To SPSecurity.RunWithElevatedPrivileges

 Scenario
  • You would like to run code as the Application Pool user rather than impersonated/delegated logged-in user within a SharePoint Application
  • You would like to run the same code outside of SharePoint in a standard Asp.Net environment or will be developing on a workstation where SharePoint is not installed
Resolution
  • You can use the System.Web.dll's Hosting.HostingEnvironment.Impersonate() method to wrap the elevated code

  • Using (System.Web.Hosting.HostingEnvironment.Impersonate())
         'Elevated Code Here
    End Using

No comments:

Post a Comment