How to get user name using Windows authentication in asp.net?

前端 未结 7 1844
抹茶落季
抹茶落季 2020-12-23 11:43

I want to get user name using Windows authentication

Actually I implemented \"Sign in as different user\",when click this button Windows security will appear there w

相关标签:
7条回答
  • 2020-12-23 12:38

    These are the different variables you have access to and their values, depending on the IIS configuration.

    Scenario 1: Anonymous Authentication in IIS with impersonation off.

    HttpContext.Current.Request.LogonUserIdentity.Name    SERVER1\IUSR_SERVER1 
    HttpContext.Current.Request.IsAuthenticated           False                    
    HttpContext.Current.User.Identity.Name                –                        
    System.Environment.UserName                           ASPNET                   
    Security.Principal.WindowsIdentity.GetCurrent().Name  SERVER1\ASPNET
    

    Scenario 2: Windows Authentication in IIS, impersonation off.

    HttpContext.Current.Request.LogonUserIdentity.Name    MYDOMAIN\USER1   
    HttpContext.Current.Request.IsAuthenticated           True             
    HttpContext.Current.User.Identity.Name                MYDOMAIN\USER1   
    System.Environment.UserName                           ASPNET           
    Security.Principal.WindowsIdentity.GetCurrent().Name  SERVER1\ASPNET
    

    Scenario 3: Anonymous Authentication in IIS, impersonation on

    HttpContext.Current.Request.LogonUserIdentity.Name    SERVER1\IUSR_SERVER1 
    HttpContext.Current.Request.IsAuthenticated           False                    
    HttpContext.Current.User.Identity.Name                –                        
    System.Environment.UserName                           IUSR_SERVER1           
    Security.Principal.WindowsIdentity.GetCurrent().Name  SERVER1\IUSR_SERVER1 
    

    Scenario 4: Windows Authentication in IIS, impersonation on

    HttpContext.Current.Request.LogonUserIdentity.Name    MYDOMAIN\USER1
    HttpContext.Current.Request.IsAuthenticated           True          
    HttpContext.Current.User.Identity.Name                MYDOMAIN\USER1
    System.Environment.UserName                           USER1         
    Security.Principal.WindowsIdentity.GetCurrent().Name  MYDOMAIN\USER1
    

    Legend
    SERVER1\ASPNET: Identity of the running process on server.
    SERVER1\IUSR_SERVER1: Anonymous guest user defined in IIS.
    MYDOMAIN\USER1: The user of the remote client.

    Source

    0 讨论(0)
提交回复
热议问题