WindowsIdentity.GetAnonymous Method

Returns a WindowsIdentity object that you can use as a sentinel value in your code to represent an anonymous user. The property value does not represent the built-in anonymous identity used by the Windows operating system.

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

public static WindowsIdentity GetAnonymous()

Return Value

Type: System.Security.Principal.WindowsIdentity
An object that represents an anonymous user.

This property returns an empty WindowsIdentity object that enables you to treat operations as anonymous. The property value does not correspond to a Windows anonymous user and cannot be used for impersonation. Also, note that the identity returned by this property is not static; each call to GetAnonymous returns a different anonymous identity.

You can use the IsAnonymous property to detect the return value from GetAnonymous. However, IsAnonymous detects both the Windows anonymous identity and the anonymous identity returned by this method. To use the latter identity, cache the GetAnonymous return value instead of relying on the IsAnonymous property.

The following code shows the use of the GetAnonymous method to return a WindowsIdentity object that represents an anonymous Windows user. This code example is part of a larger example provided for the WindowsIdentity class.

WindowsIdentity windowsIdentity = WindowsIdentity.GetAnonymous();

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft