HttpRequest.LogonUserIdentity Свойство

Определение

Получает тип WindowsIdentity для текущего пользователя.

public:
 property System::Security::Principal::WindowsIdentity ^ LogonUserIdentity { System::Security::Principal::WindowsIdentity ^ get(); };
public System.Security.Principal.WindowsIdentity LogonUserIdentity { get; }
member this.LogonUserIdentity : System.Security.Principal.WindowsIdentity
Public ReadOnly Property LogonUserIdentity As WindowsIdentity

Значение свойства

Объект WindowsIdentity для текущих параметров аутентификации служб Microsoft IIS.

Исключения

Веб-приложение работает в режиме интеграции с IIS 7, а событие PostAuthenticateRequest еще не произошло.

Примеры

В следующем примере кода показано, как получить LogonUserIdentity свойство для текущего пользователя и записать значения каждого элемента в текстовый файл. Поместите этот код на страницу ASP.NET, на которую ссылается атрибут формы ACTION .

<%@ 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)
            Response.Redirect("LoginPage.aspx");
        
        // 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.
        sw.Close();
    }  
</script>
<%@ Page Language="VB" %>
<%@ 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 INFO_DIR As String = "c:\temp\"

    Private Sub Page_Load(sender As Object, e As System.EventArgs)
   
        ' Validate that user is authenticated
        If Not (Request.LogonUserIdentity.IsAuthenticated) Then
            Response.Redirect("LoginPage.aspx")
        End If
        
        ' Create a string that contains the file path
        Dim strFilePath As String = INFO_DIR & "VB_Log.txt"
        
        Response.Write("Writing log file to " & strFilePath & "...")
        
        ' Create stream writer object and pass it the file path
        Dim sw As StreamWriter = File.CreateText(strFilePath)
        
        ' Write user info to log
        sw.WriteLine("Access log from " & DateTime.Now.ToString())
        sw.WriteLine("User: " & Request.LogonUserIdentity.User.ToString())
        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.ToString())
        sw.WriteLine("Token: " & Request.LogonUserIdentity.Token.ToString())

        ' Close the stream to the file.
        sw.Close()
    End Sub

</script>

Комментарии

Свойство LogonUserIdentity предоставляет свойства и методы объекта для текущего подключенного WindowsIdentity пользователя к Microsoft IIS (IIS). Экземпляр WindowsIdentity класса , который предоставляется с помощью LogonUserIdentity , отслеживает маркер запроса IIS и обеспечивает легкий доступ к этому маркеру для текущего HTTP-запроса, обрабатываемого внутри ASP.NET. Экземпляр WindowsIdentity класса создается автоматически, поэтому его не нужно создавать в , чтобы получить доступ к его методам и свойствам.

Применяется к