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: