简体   繁体   English

如何在 ASP.net 中获取客户端计算机用户登录?

[英]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:我认为您尝试获取以下信息:

IIS Server Variables IIS 服务器变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让客户端计算机上的程序从ASP.NET页面运行? - How can I get a program on a client machine to run from an ASP.NET page? 如何获取客户端计算机的窗口原理ID(asp.net) - How to get window principle id of client machine (asp.net) 如何在 ASP.NET / C# 中获取客户端计算机名称? - How to get Client Machine Name in ASP.NET / C#? 如何在asp.net中获取客户端机器的临时路径? - How to get temporary path of client machine in asp.net? 如何从Facebook OAuth登录名将用户的电子邮件返回到我的asp.net网络表单应用程序? - How can I get the user's email returned to my asp.net web forms app from Facebook OAuth login? Asp.Net Boilerplate ,,如何获取当前登录用户? - Asp.Net Boilerplate,, How to Get current Login User? 如何在ViewComponent Asp.Net Core中获取当前登录用户 - How get current login user in ViewComponent Asp.Net Core 是否可以在 asp.net web 应用程序中获取客户端计算机操作系统用户名 - Is it possible to get client machine OS user name in asp.net web application 在ASP.NET Core上使用Identity登录后,如何直接获取用户详细信息? - How do I get the user details straight after login using Identity on ASP.NET Core? 如何在 ASP.NET 中获取用户的客户端 IP 地址? - How to get a user's client IP address in ASP.NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM