如何解决如何获得ASP.net中的客户端计算机用户登录名?
| 在Localhost上,调用此代码时,我的用户名是\'MTA \':string opl = HttpContext.Current.User.Identity.Name.ToString();
TextBox1.Text = opl.Substring(opl.IndexOf(@\"\\\") + 1);
或此代码:
string opl = System.Environment.UserName.ToString();
TextBox1.Text = opl.Substring(opl.IndexOf(@\"\\\") + 1);
但是在从Windows Server发布和访问网站之后。我的用户名现在为\'SRVCMAN \'。
解决方法
我相信您正在寻求实现Windows身份验证模式。
请参阅以下文章并阅读有关它的内容:
如何:在ASP.NET 2.0中使用Windows身份验证
解释:ASP.NET 2.0中的Windows身份验证
如何在ASP.NET中实现Windows身份验证和授权
使用Windows身份验证对用户进行身份验证
,为此,请进入IIS,单击
Authentication
并禁用Anonymous Authentication
并启用Windows Authentication
然后使用以下代码:
var ident = (System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity;
If(!ident.IsAnonymous && ident.IsAuthenticated)
{
var loginUsername = ident.Name;
}
, // will return the host name making the request
string s = Request.ServerVariables[\"REMOTE_HOST\"] ;
-----------------------------------------------------------------
// will return the computer name
string s = Request.ServerVariables[\"SERVER_NAME\"] ;
-----------------------------------------------------------------
//will return Windows account for the user.
string s = Request.ServerVariables[\"AUTH_USER\"] ;
-----------------------------------------------------------------
我认为您尝试获取以下信息:
IIS服务器变量
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。