asp.net怎样获取客户端Windows用户名?

Nick_Ngai Nick_Ngai 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我的项目发布在服务器,想做一个功能,当客户端访问网站时可以获取到这个客户端的Windows登陆用户名,
在网上找了很多方法都不行,如下:
1. System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
string strName = p.Identity.Name;
2.string strName = HttpContext.Current.User.Identity.Name;
这两种去不到值,Web.config也配置了如下:
<authentication mode="Windows"/>
<identity impersonate="true"/>
3.string userName = Environment.UserName;
4.WindowsIdentity identity = WindowsIdentity.GetCurrent();
string userName = identity.Name;
3和4只是获取本地用户(服务器)
5.Page.Request.UserHostAddress;
Page.Request.UserHostName
这两种只是获取客户端IP地址

谁知道怎样获取客户端Windows用户名?
2和4虽然能够实现,但是不够好,因为会弹出登陆验证,即使能够做到不弹验证,他们也是采用Coolie方式,所以获取的用户名并不一定准确。

JS方法如下:
var WshNetwork = new ActiveXObject("WScript.Network");
alert("Domain_Name =" + WshNetwork.UserDomain);
alert("Computer_Name =" + WshNetwork.ComputerName);
alert("User_Name =" + WshNetwork.UserName);
獲取JS有什麽方法?上面的要設置IE安全性才行,所以不是很好
...全文

相关推荐

评论 14
收藏 已收藏
分享
返回顶部
Nick_Ngai
.NET社区 62,274 成员 668,968 内容