Solved

WindowsIdentity.GetCurrent().User

Posted on 2008-10-23
6
1,709 Views
Last Modified: 2013-12-17
When I use

WindowsIdentity.GetCurrent().User

a long a number is returned. Is this a static number or does it change everytime I long in.
0
Comment
Question by:Mr_Shaw
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22787733
I guess this long number is the address of the object returned.
If you need to get the user name use
System.Security.Principal.WindowsIdentity.GetCurrent().Name
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 22788350
.User is returning the SID.  Based on what I can find on Wikipedia, SID is assigned by the Domain controller during the log on process.  So it sounds like it is a value that can change.  I could see it being the same on a relatively static network.  But otherwise, the definision seems to indicated it can change.
http://en.wikipedia.org/wiki/Security_Identifier
0
 

Author Comment

by:Mr_Shaw
ID: 22794451
Is it possible for there to be two users with the same name on a microsoft domain. for example two Mr bloggs?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 13

Expert Comment

by:TechTiger007
ID: 22794485

there could be two users with same name but they will have different user ids
0
 

Author Comment

by:Mr_Shaw
ID: 22794856
Is this user ID static or can it change every time the user logs on to the network.

How do I return the user ID. I just had a look and intelliesense does not list user ID?
0
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 total points
ID: 22795937
User id is the id (username) used by user to login. This will be unique for each user in a network.

System.Security.Principal.WindowsIdentity.GetCurrent().Name
will give you "<domain>\<userid>". You can retrieve the string and split with "\" (backslash) as seperator and you will get the user id.

string domainuserid = System.Security.Principal.WindowsIdentity.GetCurrent().Name
string domainname = "";
string userid = "";
if(domainuserid != null)
{
string[] arr = domainuserid.split('\');
if(arr.Length ==2)
  {
    domainname = arr[0];
    userid = arr[1];
  }
else if(arr.Length == 1)
userid = arr[0];
}

there could be syntax errors. You can start with this
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to count occurrences of each item in an array.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now