Answered by:
How to get the id of a windows user

Question
-
User-1355245701 posted
I would like to get the id of a logged in windows user when they call a web page. Not the machine name/username but rather the email address that they used to log in to windows. What is the use of a machine name/user name if it is not unique? The code below tries to get customer TONY-DESKTOP/Tony from the database instead of Tony@bigpond.com. Given I use Windows authentication for my website requests, why should I not be able to access the windows logon id. There will be a huge requirement to do so.
Protected Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Trees.tre = New Trees.Tree.Node(New Trees.Tree.Tree()) Trees.tre.Populate() RefreshDisplay(Trees.tre.Customers(User.Identity.Name) End If End Sub
Wednesday, August 17, 2016 9:48 AM
Answers
-
User283571144 posted
Hi trogan,
. Not the machine name/username but rather the email address that they used to log in to windows. What is the use of a machine name/user name if it is not unique? The code below tries to get customer TONY-DESKTOP/Tony from the database instead of Tony@bigpond.com. Given I use Windows authentication for my website requests, why should I not be able to access the windows logon id.According to your description, I suggest you could use “User.Identity.Name” get the name of user.
Then you could use “System.DirectoryServices” "DirectorySearcher.FindOne" method to query the Active directory to search for user and then get its properties such as the email.
More details, you could refer to follow link:
DirectorySearcher.FindOne:
Best Regards,
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 18, 2016 6:44 AM
All replies
-
User283571144 posted
Hi trogan,
. Not the machine name/username but rather the email address that they used to log in to windows. What is the use of a machine name/user name if it is not unique? The code below tries to get customer TONY-DESKTOP/Tony from the database instead of Tony@bigpond.com. Given I use Windows authentication for my website requests, why should I not be able to access the windows logon id.According to your description, I suggest you could use “User.Identity.Name” get the name of user.
Then you could use “System.DirectoryServices” "DirectorySearcher.FindOne" method to query the Active directory to search for user and then get its properties such as the email.
More details, you could refer to follow link:
DirectorySearcher.FindOne:
Best Regards,
Brando
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 18, 2016 6:44 AM -
User-693639306 posted
thank you. yes. that's right, i need
Thursday, August 18, 2016 8:33 AM