Solved

WindowsIdentity.GetCurrent().User

Posted on 2008-10-23
6
1,767 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
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

636 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