使用ASP.NET获得AD帐号 “域\用户名”

1.在IIS中将访问方式更改为不允许匿名访问
2.在Web.config中将验证方式更改为
   <identity impersonate="true"/>
   <authentication mode="Windows" />
3.在源代码中使用
string username= Security.Principal.WindowsIdentity.GetCurrent().Name
string[] info = username.Split(new char[1] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
 
Domain:info[0]
Name: info[1]
原文地址:https://www.cnblogs.com/top5/p/2253667.html