The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
GenericIdentity Class
.NET Framework 3.0
Represents a generic user.
Namespace: System.Security.Principal
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
[SerializableAttribute] [ComVisibleAttribute(true)] public class GenericIdentity : IIdentity
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public class GenericIdentity implements IIdentity
SerializableAttribute ComVisibleAttribute(true) public class GenericIdentity implements IIdentity
Not applicable.
An identity object represents the user on whose behalf the code is running.
| Topic | Location |
|---|---|
| How to: Create GenericPrincipal and GenericIdentity Objects | .NET Framework: Security |
| How to: Create GenericPrincipal and GenericIdentity Objects | .NET Framework: Security |
The following example shows the use of members of the GenericIdentity class.
using System; using System.Security.Principal; class GenericIdentityMembers { [STAThread] static void Main(string[] args) { // Create a GenericIdentity object with no authentication type // specified. GenericIdentity defaultIdentity = new GenericIdentity("DefaultUser"); // Retrieve a GenericIdentity created from current WindowsIdentity // values. GenericIdentity currentIdentity = GetGenericIdentity(); ShowIdentityPreferences(new GenericIdentity("")); ShowIdentityPreferences(defaultIdentity); ShowIdentityPreferences(currentIdentity); Console.WriteLine("The sample completed successfully; " + "press Enter to continue."); Console.ReadLine(); } // Print identity preferences to the console window. private static void ShowIdentityPreferences( GenericIdentity genericIdentity) { // Retrieve the name of the generic identity object. string identityName = genericIdentity.Name; // Retrieve the authentication type of the generic identity object. string identityAuthenticationType = genericIdentity.AuthenticationType; Console.WriteLine("Name: " + identityName); Console.WriteLine("Type: " + identityAuthenticationType); // Verify that the user's identity has been authenticated // (was created with a valid name). if (genericIdentity.IsAuthenticated) { Console.WriteLine("The user's identity has been authenticated."); } else { Console.WriteLine("The user's identity has not been " + "authenticated."); } Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~"); } // Create generic identity based on values from the current // WindowsIdentity. private static GenericIdentity GetGenericIdentity() { // Get values from the current WindowsIdentity. WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent(); // Construct a GenericIdentity object based on the current Windows // identity name and authentication type. string authenticationType = windowsIdentity.AuthenticationType; string userName = windowsIdentity.Name; GenericIdentity authenticatedGenericIdentity = new GenericIdentity(userName, authenticationType); return authenticatedGenericIdentity; } }
import System.*;
import System.Security.Principal.*;
class GenericIdentityMembers
{
/** @attribute STAThread()
*/
public static void main(String[] args)
{
// Create a GenericIdentity object with no authentication type
// specified.
GenericIdentity defaultIdentity = new GenericIdentity("DefaultUser");
// Retrieve a GenericIdentity created from current WindowsIdentity
// values.
GenericIdentity currentIdentity = GetGenericIdentity();
ShowIdentityPreferences(new GenericIdentity(""));
ShowIdentityPreferences(defaultIdentity);
ShowIdentityPreferences(currentIdentity);
Console.WriteLine("The sample completed successfully; "
+ "press Enter to continue.");
Console.ReadLine();
} //main
// Print identity preferences to the console window.
private static void ShowIdentityPreferences(GenericIdentity genericIdentity)
{
// Retrieve the name of the generic identity object.
String identityName = genericIdentity.get_Name();
// Retrieve the authentication type of the generic identity object.
String identityAuthenticationType
= genericIdentity.get_AuthenticationType();
Console.WriteLine("Name: " + identityName);
Console.WriteLine("Type: " + identityAuthenticationType);
// Verify that the user's identity has been authenticated
// (was created with a valid name).
if (genericIdentity.get_IsAuthenticated()) {
Console.WriteLine("The user's identity has been authenticated.");
}
else {
Console.WriteLine("The user's identity has not been "
+ "authenticated.");
}
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~");
} //ShowIdentityPreferences
// Create generic identity based on values from the current
// WindowsIdentity.
private static GenericIdentity GetGenericIdentity()
{
// Get values from the current WindowsIdentity.
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
// Construct a GenericIdentity object based on the current Windows
// identity name and authentication type.
String authenticationType = windowsIdentity.get_AuthenticationType();
String userName = windowsIdentity.get_Name();
GenericIdentity authenticatedGenericIdentity
= new GenericIdentity(userName, authenticationType);
return authenticatedGenericIdentity;
} //GetGenericIdentity
} //GenericIdentityMembers
Windows Server 2000 SP4, Windows Millennium Edition, 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.Community Additions
Show: