获取客户端windows当前登入账号
1.获取客户端当前用户
首先IIS的权限不能设为匿名访问,设为整合Windows访问。 这样在域中就可得到客户端登入电脑账号,域外则需要输入账号密码,不推荐使用,所以此方法只推荐给小型内部web开发。
Page.User.Identity.Name
2.通过注册表获取本机当前登入用户
private string GetRegistData(string name)
{
string registData;
RegistryKey hkml = Registry.Users;
RegistryKey software = hkml.OpenSubKey("Software", true);
RegistryKey microsoft = software.OpenSubKey("Microsoft", true);
RegistryKey windows = microsoft.OpenSubKey("Windows", true);
RegistryKey currentversion = windows.OpenSubKey("CurrentVersion", true);
RegistryKey explorer = currentversion.OpenSubKey("Explorer", true);
registData = explorer.GetValue(name, "").ToString();
return registData;
}
传入的name为你要取得值。