简体   繁体   中英

Get user name and email address in asp.net form

Each user of my asp.net forms app logs into a PC with their Active Directory credentials. How could the ASP.NET forms app get the user name and the email address currently logged into the PC?

There is no guaranteed way to find out which user they are logged into their computer with. However, you can:

  1. Enable Windows Authentication so they need to authenticate with your website with an AD account
  2. Add your website to the Trusted Sites in the Internet Options on their computer (this can be done in group policy) so that IE and Chrome will automatically send the credentials of the currently-logged-on user account. (Firefox uses its own network.negotiate-auth.delegation-uris setting)

If you skip step 2, then the user will be prompted for credentials. If the credentials sent in step 2 fail for whatever reason (for example, they are logged in with a local account instead of a domain account), the user will be prompted for credentials. Then they can type in whatever AD account they want, which may not be the same as what they are logged into their computer with. That's why I say that there is no 100% guaranteed way to know what account they are logged into their computer with.

If only some of your users have AD accounts, and some don't, then you can use split Forms and Windows authentication. I've done this before and described how I did it in a past answer .

使用HttpContext.Current.Request.LogonUserIdentity获取用户名,而不是查询AD以获取电子邮件检查如何从Active Directory中获取用户的电子邮件地址?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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