Impersonation in ASP.NET
Post # 29 permalink Topic #29 by mreschke on 2008-02-29 09:08:31 (viewed 604 times)

Impersonation is the concept whereby an application executes under the \
context of the identity of the client that is accessing the \
application. This is achieved by using the access token provided by \
IIS.

Can impersonate entire website by editing the web.config or impersonate chunks of code in the codebehind.
Very usefull when accessing folders on a remote server that has no domain

Impersonate entire website with web.config[-][- -][++]

Script Snippet

Impersonate in the Code Behind (ASP.NET)[-][- -][++]

Imports[-][- -][++]

Code Snippet
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.Web.Security

Script[-][- -][++]

Script Snippet

Impersonate in the Code Behind (C++.NET)[-][- -][++]

Imports[-][- -][++]

Code Snippet
using System.Runtime.InteropServices;
using System.Security.Principal;

Script[-][- -][++]

Script Snippet

Calling Impersonate[-][- -][++]

Code Snippet
Whatever chunk you want to impersonate, just use

if(impersonateValidUser("administrator", "dyna-web2", "password"))
{
    //do stuff with impersonated users here
}
undoImpersonation();