WindowsIdentity.Impersonate Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Impersonates the user represented by the WindowsIdentity object.

Namespace:   System.Security.Principal
Assembly:  mscorlib (in mscorlib.dll)

abstract Impersonate : unit -> WindowsImpersonationContext
override Impersonate : unit -> WindowsImpersonationContext

Return Value

Type: System.Security.Principal.WindowsImpersonationContext

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

Exception Condition
InvalidOperationException

An anonymous identity attempted to perform an impersonation.

SecurityException

A Win32 error occurred.

On Windows NT platforms, the current user must have sufficient rights to allow impersonation.

Notes to Implementers:

Because Microsoft Windows 98 and Windows Millennium Edition (Windows Me) platforms do not have user tokens, impersonation cannot take place on those platforms.

Notes to Callers:

After using Impersonate, it is important to call the Undo method to end the impersonation.

The following example demonstrates how to obtain a Windows account token by calling the unmanaged Win32 LogonUser function, and how to use that token to impersonate another user and then revert to the original identity.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: