Javascript 在不使用activex对象的情况下获取windows用户名

Javascript 在不使用activex对象的情况下获取windows用户名,javascript,asp.net,windows,iis,activexobject,Javascript,Asp.net,Windows,Iis,Activexobject,是否可以在不使用activex对象的情况下获取托管在远程服务器上的asp.net中的客户端windows用户名 我使用了以下代码 Response.Write("HttpContext.Current.Request.LogonUserIdentity.Name " & HttpContext.Current.Request.LogonUserIdentity.Name) Response.Write("<br/>") Res

是否可以在不使用activex对象的情况下获取托管在远程服务器上的asp.net中的客户端windows用户名

我使用了以下代码

        Response.Write("HttpContext.Current.Request.LogonUserIdentity.Name  " & HttpContext.Current.Request.LogonUserIdentity.Name)
        Response.Write("<br/>")
        Response.Write("HttpContext.Current.Request.IsAuthenticated " & HttpContext.Current.Request.IsAuthenticated)
        Response.Write("<br/>")
        Response.Write("HttpContext.Current.User.Identity.Name " & HttpContext.Current.User.Identity.Name)
        Response.Write("<br/>")
        Response.Write("System.Environment.UserName " & System.Environment.UserName)
        Response.Write("<br/>")
        Response.Write("Security.Principal.WindowsIdentity.GetCurrent().Name() " & System.Security.Principal.WindowsIdentity.GetCurrent().Name())
        Response.Write("<br/>")

但它总是给我服务器用户名,而不是客户端用户名。

您可以尝试使用ServerVariables

string Hostname=Request.ServerVariables["REMOTE_HOST"];
string Username=Request.ServerVariables["REMOTE_USER"];

如果您使用的是Windows身份验证,则此行将起作用

Response.Write("HttpContext.Current.User.Identity.Name " & HttpContext.Current.User.Identity.Name)

ref:

您的虚拟目录/应用程序是如何配置的?只有在使用Windows身份验证时才可能。这是可能的,但即使存在,您在每个浏览器中访问此信息的方式也不同。例如,您使用的Mozilla FireFox。因此,javascript将首先检测浏览器,然后相应地访问windows用户名。另外,如果您使用C,您可以使用@AdrianoRepetti,使用windows身份验证仅在intranet上有效,而在internet上无效,不是吗?是的,仅在intranet中有效,因为使用JavaScript无法从不受信任的站点访问该信息可能是一个安全问题。[远程用户]在用户名映射到Windows帐户之前,从客户端发送的授权标头派生的用户名。如果在Web服务器上安装了将传入用户映射到帐户的身份验证筛选器,请使用LOGON\u USER查看映射的用户名。