[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1845
  • Last Modified:

WindowsIdentity.GetCurrent().User

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
Mr_Shaw
Asked:
Mr_Shaw
  • 3
  • 2
1 Solution
 
TechTiger007Commented:
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
 
HooKooDooKuCommented:
.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
 
Mr_ShawAuthor Commented:
Is it possible for there to be two users with the same name on a microsoft domain. for example two Mr bloggs?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
TechTiger007Commented:

there could be two users with same name but they will have different user ids
0
 
Mr_ShawAuthor Commented:
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
 
TechTiger007Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now