Solved

WindowsIdentity.GetCurrent().User

Posted on 2008-10-23
6
1,748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

734 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