Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All
I wanna get the userid of the loggedin user.I got the username and machine name..can some one help me out??
C#
static void Main(string[] args)

{

    Console.WriteLine("Current Logged UserName: " + Environment.UserName);
    Console.WriteLine("Local Machine Name: " + Environment.MachineName);
    Console.WriteLine("Local Machine Name: " + Dns.GetHostName()); 
    // Dns from System.Net

    // Console.WriteLine("IPHostEntry: " + Dns.GetHostByName(Dns.GetHostName)); 
    // Dns from System.Net

    IPHostEntry ip = Dns.GetHostEntry (Dns.GetHostName());
    IPAddress[] IPaddr = ip.AddressList;

    for (int i = 0; i < IPaddr.Length; i++)
        {Console.WriteLine("IP Address {0}: {1} ", i, IPaddr[i].ToString());}

    Console.ReadLine();

}
Posted
Updated 3-May-13 0:07am
v2
Comments
Pheonyx 3-May-13 6:08am    
What do you mean by the userid? In windows I believe a users ID is their username.
sindhuan 3-May-13 6:10am    
everytime we create a user an ID(may be a autogenerated number)will be craeted along with it..I want that
Pheonyx 3-May-13 6:14am    
Are you talking about a windows user? or one specific to your program?
You could try reading this, it might allow you to do something, but I'm not sure.

http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#34
Naz_Firdouse 3-May-13 9:48am    
so you will store the user info somewhere else.right?
like in DB...
so once the user login, get the ID from DB by accessing the database from your app
ThePlatypus 3-May-13 12:21pm    
Are you using Windows authentication or other type?

1 solution

You alreayd have it. It's Environment.UserName. Actually, it a combination of Environment.UserDomain and Environment.UserName.

Or...you can use System.Security.Principal.WindowsIdentity.GetCurrent().Name
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900