Get user name from the web client in Active Directories. [ No using Page.user]

 Usually we using the  Page.User.Identity.Name to get the web client user name . But if we are in the Active Directores enviroment and try to do this will be failed. So we need to set the web server like show in below firstly.

Now the web server will replace the ISUER_MachineName login model as window authentication model which take the credentials from windows AD logged user.

Finally, we can using 3 types of method to get the web-client user name.

 [1] System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
            
p.Identity.Name;
[2] HttpContext.Current.User.Identity.Name.ToString();
[3] Request.ServerVariables["AUTH_USER"].ToString();
原文地址:https://www.cnblogs.com/zencorn/p/2016040.html