This documentation is archived and is not being maintained.

HostingEnvironment.Impersonate Method (IntPtr, String)

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

Namespace: System.Web.Hosting
Assembly: System.Web (in system.web.dll)

public static IDisposable Impersonate (
	IntPtr userToken,
	string virtualPath
)
public static IDisposable Impersonate (
	IntPtr userToken, 
	String virtualPath
)
public static function Impersonate (
	userToken : IntPtr, 
	virtualPath : String
) : IDisposable
Not applicable.

Parameters

userToken

The handle of a Windows account token.

virtualPath

The path to the requested resource.

Return Value

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

Exception typeCondition

HttpException

The process cannot impersonate.

The Impersonate method impersonates the user that results after applying all identity 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.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Show: