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

When i run my application on mysystem/localhost it gives me correct username. but when i host my application on IIS and then open application on other user's pc then it should show that pc's username. but it doesn't.

how to retrieve username of that pc?

I have tried below lines of code to get the username.

C#
if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
     string userName = "Hello, " + System.Web.HttpContext.Current.User.Identity.Name;
}

string ddd = System.Net.Dns.GetHostName();

string s = Page.User.Identity.Name;

string sss= System.Environment.UserName;

string test= HttpContext.Current.Request.LogonUserIdentity.ToString();


are there any other solutions to get the username?

thanks
Posted
Updated 16-Aug-12 20:50pm
v2
Comments
ZurdoDev 16-Aug-12 9:48am    
What does it show? Make sure anonymous access is turned off.

1 solution

You need to study how a web application works and the client server basics.

The server code you have written executes on the server and only sends the response to the user. And since your code is executing on the server, it will get the machine details ( mysystem/localhost) of the server and NOT of the user who is browsing it.

To make the matter worse, you have not posted the code.

Ask me if you need any other details...
 
Share this answer
 
v2
Comments
kk2014 17-Aug-12 2:46am    
Hi aspnet_regiis,

i have tried these lines of codes to get username.

if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
string userName = "Hello, " + System.Web.HttpContext.Current.User.Identity.Name;
}
string ddd = System.Net.Dns.GetHostName();

string s = Page.User.Identity.Name;

string sss= System.Environment.UserName;

string test= HttpContext.Current.Request.LogonUserIdentity.ToString();


let me know are there any other solutions for the same.

thanks.

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