Quicknote: Equivalent to SPSecurity.RunWithElevatedPrivileges in standard asp.net (4.0)

I have an asp.net web app that must execute code under the context of the current user (via identity impersonate, as it needs to call out to various resources). There are some blocks of code, such as writing exceptions to the event log that must run as the app pool account.

In SharePoint, (which has asp.net set up very similar to my web app), there is SPSecurity.RunWithElevatedPrivileges. This ensure a block of code runs as the app pool account. The equivalent in asp.net is as follows:

using (System.Web.Hosting.HostingEnvironment.Impersonate())
{
}

http://msdn.microsoft.com/en-us/library/system.web.hosting.hostingenvironment.impersonate.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>