HostingEnvironment.Impersonate Method

Definition

Allows code to impersonate a different user.

Overloads

Impersonate()

Impersonates the user represented by the application identity.

Impersonate(IntPtr)

Impersonates the user represented by the specified user token.

Impersonate(IntPtr, String)

Impersonates the user specified by the configuration settings for the specified virtual path, or the specified user token.

Impersonate()

Impersonates the user represented by the application identity.

public:
 static IDisposable ^ Impersonate();
public static IDisposable Impersonate ();
static member Impersonate : unit -> IDisposable
Public Shared Function Impersonate () As IDisposable

Returns

An IDisposable object that represents the Windows user prior to impersonation; this object can be used to revert to the original user's context.

Exceptions

The process cannot impersonate.

Applies to

Impersonate(IntPtr)

Impersonates the user represented by the specified user token.

public:
 static IDisposable ^ Impersonate(IntPtr token);
public static IDisposable Impersonate (IntPtr token);
static member Impersonate : nativeint -> IDisposable
Public Shared Function Impersonate (token As IntPtr) As IDisposable

Parameters

token
IntPtr

nativeint

The handle of a Windows account token.

Returns

An IDisposable object that represents the Windows user prior to impersonation; this object can be used to revert to the original user's context.

Exceptions

The process cannot impersonate.

Applies to

Impersonate(IntPtr, String)

Impersonates the user specified by the configuration settings for the specified virtual path, or the specified user token.

public:
 static IDisposable ^ Impersonate(IntPtr userToken, System::String ^ virtualPath);
public static IDisposable Impersonate (IntPtr userToken, string virtualPath);
static member Impersonate : nativeint * string -> IDisposable
Public Shared Function Impersonate (userToken As IntPtr, virtualPath As String) As IDisposable

Parameters

userToken
IntPtr

nativeint

The handle of a Windows account token.

virtualPath
String

The path to the requested resource.

Returns

An IDisposable object that represents the Windows user prior to impersonation; this object can be used to revert to the original user's context.

Exceptions

The process cannot impersonate.

Remarks

The Impersonate method impersonates the user that results after applying all elements in the configuration settings affecting the specified virtual path. If an identity element is not specified for the virtual path, the Impersonate method impersonates the specified Windows account.

Applies to