[英]How can I get client machine user login in ASP.net?
On Localhost my username is 'MTA' when calling this code:在本地主机上调用此代码时,我的用户名是“MTA”:
string opl = HttpContext.Current.User.Identity.Name.ToString();
TextBox1.Text = opl.Substring(opl.IndexOf(@"\") + 1);
OR this code:或此代码:
string opl = System.Environment.UserName.ToString();
TextBox1.Text = opl.Substring(opl.IndexOf(@"\") + 1);
But after publishing and accessing the website from a Windows Server.但是在从 Windows 服务器发布和访问网站之后。 My username is now 'SRVCMAN'.
我的用户名现在是“SRVCMAN”。
For this to work go into IIS click on Authentication
and disable Anonymous Authentication
and enable Windows Authentication
为此,go 进入 IIS 单击
Authentication
并禁用Anonymous Authentication
并启用Windows Authentication
And then use this code:然后使用以下代码:
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"] ;
-----------------------------------------------------------------
I think you try to get information like this:我认为您尝试获取以下信息:
I believe you are looking for implementing Windows Authentication Mode .我相信您正在寻找实现Windows Authentication Mode 。
Refer to the following articles and read about it:请参阅以下文章并阅读相关内容:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.