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

속성 값

현재 Microsoft IIS(인터넷 정보 서비스) 인증 설정의 WindowsIdentity 개체입니다.

예외

웹 애플리케이션은 IIS 7 통합 모드로 실행되고 있으며 PostAuthenticateRequest 이벤트가 아직 발생하지 않았습니다.

예제

다음 코드 예제에서는 현재 사용자에 LogonUserIdentity 대 한 속성을 검색 하 고 텍스트 파일에서 각 항목의 값을 작성 하는 방법에 설명 합니다. 양식 ACTION 의 특성에서 참조하는 ASP.NET 페이지에 이 코드를 배치합니다.

<%@ 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 현재 연결된 사용자가 IIS(Microsoft 인터넷 정보 서비스)에 대한 개체의 WindowsIdentity 속성과 메서드를 노출합니다. 에서 노출 LogonUserIdentity 되는 클래스의 WindowsIdentity instance IIS 요청 토큰을 추적하고 ASP.NET 내에서 처리 중인 현재 HTTP 요청에 대해 이 토큰에 쉽게 액세스할 수 있도록 합니다. 클래스의 WindowsIdentity instance 자동으로 만들어지므로 메서드 및 속성에 액세스하기 위해 를 생성할 필요가 없습니다.

적용 대상