Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How can I get the account information I am logged in. Like if I am logged in with stalin_king into one machine, then how can I get that thorugh ASP.Net.

I am using WindowsIdentity.GetCurrent().Name.ToString().Trim();, but this is giving the server account name where as I want the user name of the machine where I open this site.

Any ideas.
Posted
Updated 16-Feb-11 22:46pm
v2
Comments
Sandeep Mewara 17-Feb-11 4:47am    
If it's your account name, be it server or any other machine, names are same as it's picked from Active directory.

Looks like you are looking for something else. Edit and rephase your question.
Sreenath Gv 17-Feb-11 4:48am    
I want the account name of the machine where I have opened my site.
OriginalGriff 17-Feb-11 4:51am    
Do you mean the client machine user account name?
Or the Server account name?
Sreenath Gv 17-Feb-11 4:49am    
I hope you got it nw..!

It depends what mode you have your Asp.Net authentication set to. Here's an article which briefly describes the options

http://www.4guysfromrolla.com/articles/031204-1.aspx[^]

Now, I'm assuming you want to work with 'Windows Authentication' since you want to get the account name of the user connecting to the site. In which case, you'll need to make sure this mode is set in your web.config and that you have your IIS site set to use 'Integrated Authentication'

You could then use something like this to get the Windows Principal object

// Obtain the authenticated user's Identity
WindowsPrincipal winPrincipal = (WindowsPrincipal)HttpContext.Current.User;

Just accessing the HttpContext.Current.User object should give you what you want though

Further reading

http://msdn.microsoft.com/en-us/library/ff647076.aspx[^]
 
Share this answer
 
You can get the name of the machine through Environment.MachineName
 
Share this answer
 
Comments
soni uma 17-Feb-11 4:53am    
Short and sweet...
Manas Bhardwaj 17-Feb-11 5:30am    
No it is not. It will always give you the Server name i.e. Environment where your code is being executed.
Manas Bhardwaj 17-Feb-11 5:30am    
OP wants the client m/c name and not the server name.
Well, I am not sure if you application is for Internet or Intranet.
If it is intended for internet, I am afraid that would not be possible. Or I should say ASP.Net does not have a way to do it, you can always write some kind of ActiveX control to do this.

Now comes the intranet thingie. You can try this one:

Dim host As System.Net.IPHostEntry
host = System.Net.Dns.GetHostByAddress(Request.ServerVariables.Item("REMOTE_HOST"))
string strComputerName = host.HostName
 
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