简体   繁体   English

在不使用ActiveX对象的情况下获取Windows用户名

[英]Get windows username without using activex object

is it possible to get clients windows username in asp.net hosted in remote server without using activex object ? 是否可以在不使用activex对象的情况下在远程服务器中托管的asp.net中获取客户端Windows用户名?

i have used following code 我已经使用以下代码

        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/>")

but it is always giving me server user name not the clients username . 但是它总是给我服务器用户名而不是客户端用户名。

You can try to use ServerVariables 您可以尝试使用ServerVariables

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

this line will work if you are using "Windows Authentication" 如果您使用的是“ Windows身份验证”,则此行将起作用

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

ref: MSDN 参考: MSDN

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM