vb.net 从启用了 Windows 身份验证和服务帐户的 Web 服务器中运行的 Web 应用程序获取客户端用户名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15280402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:39:46  来源:igfitidea点击:

Get Client User Name from a Web Application running in a Web Server with Windows Auth Enabled & Service Account

asp.netvb.netusernamenetworkcredentials

提问by Eddy V

I have encounter the following issue while deploying my application into a WebServer,

我在将应用程序部署到 WebServer 时遇到以下问题,

The code that i have was "Usercheck = My.User.Name" but that will return the Service Account for the instance that is running my webapp, so i need to display "evilla" which is my current windows credential, when i try to connect for the first time to the webapp it asks for my network credentials.

我拥有的代码是“Usercheck = My.User.Name”,但这将返回运行我的 webapp 的实例的服务帐户,所以我需要显示“evilla”,这是我当前的 Windows 凭据,当我尝试第一次连接到它要求我的网络凭据的 web 应用程序。

Is it possible to grab my windows username and not the service account?? (i'm conecting remotely to the app)

是否可以获取我的 Windows 用户名而不是服务帐户?(我正在远程连接到应用程序)

i have tried:

我试过了:

   'Usercheck = Request.LogonUserIdentity.Name
    Usercheck = HttpContext.Current.Request.LogonUserIdentity.Name
    TextBox4_AddDataControl.Text = Usercheck
    TextBox6_AddDataControl.Text = Environment.UserName

Am i missing something??

我错过了什么吗?

Note: i'm getting from the above code "NA/SRS-SA" (service account)

注意:我从上面的代码“NA/SRS-SA”(服务帐户)中得到

Thank you!!

谢谢!!

回答by Eddy V

After more research, the below code returned the user that is logged at the time in the service account.

经过更多研究,以下代码返回了当时登录服务帐户的用户。

        TextBox6_AddDataControl1.Text = Request.ServerVariables("LOGON_USER")

Hope it helps someone in the future! :)

希望它可以帮助未来的人!:)