HttpRequest.LogonUserIdentity Property


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

Gets the WindowsIdentity type for the current user.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)

public WindowsIdentity LogonUserIdentity {
	[AspNetHostingPermissionAttribute(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Medium)]

Property Value

Type: System.Security.Principal.WindowsIdentity

A WindowsIdentity object for the current Microsoft Internet Information Services (IIS) authentication settings.

Exception Condition

The Web application is running in IIS 7 integrated mode and the PostAuthenticateRequest event has not yet been raised.

The LogonUserIdentity property exposes the properties and methods of the WindowsIdentity object for the currently connected user to Microsoft Internet Information Services (IIS). The instance of the WindowsIdentity class that is exposed by LogonUserIdentity tracks the IIS request token and provides easy access to this token for the current HTTP request being processed inside of ASP.NET. An instance of the WindowsIdentity class is automatically created so it does not need to be constructed to in order to gain access to its methods and properties.

The following code example shows how to retrieve the LogonUserIdentity property for the current user and write out the values of each item in a text file. Place this code on the ASP.NET page referenced by the form's ACTION attribute.

<%@ Page Language="C#" %>
<%@ import Namespace="System.IO" %>

<script runat="server">

    /* NOTE: To use this sample, create a c:\temp  folder,
    *  add the ASP.NET account (in IIS 5.x <machinename>\ASPNET,
    *  in IIS 6.x NETWORK SERVICE), and give it write permissions
    *  to the folder.*/

    private const string INFO_DIR = @"c:\temp\";

    private void Page_Load(object sender, System.EventArgs e)
        // Validate that user is authenticated
        if (!Request.LogonUserIdentity.IsAuthenticated)

        // Create a string that contains the file path
        string strFilePath = INFO_DIR + "CS_Log.txt";

        Response.Write("Writing log file to " + strFilePath + "...");

        // Create stream writer object and pass it the file path
        StreamWriter sw = File.CreateText(strFilePath);

        // Write user info to log
        sw.WriteLine("Access log from " + DateTime.Now.ToString());
        sw.WriteLine("User: " + Request.LogonUserIdentity.User);
        sw.WriteLine("Name: " + Request.LogonUserIdentity.Name);
        sw.WriteLine("AuthenticationType: " + Request.LogonUserIdentity.AuthenticationType);
        sw.WriteLine("ImpersonationLevel: " + Request.LogonUserIdentity.ImpersonationLevel);
        sw.WriteLine("IsAnonymous: " + Request.LogonUserIdentity.IsAnonymous);
        sw.WriteLine("IsGuest: " + Request.LogonUserIdentity.IsGuest);
        sw.WriteLine("IsSystem: " + Request.LogonUserIdentity.IsSystem);
        sw.WriteLine("Owner: " + Request.LogonUserIdentity.Owner);
        sw.WriteLine("Token: " + Request.LogonUserIdentity.Token);

        // Close the stream to the file.

.NET Framework
Available since 2.0
Return to top