Click here to Skip to main content
15,916,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am getting user name by using the following code:
txtName.Text = Environment.UserName;
I have deployed the code in IIS and while running the application then i am getting
user name as "NETWORK SERVICE" in the textbox instead of logged user name.
And I am using the FORMS authentication mode. (this is mandatory)
Thanks in advance.
Posted

1 solution

The FormsAuthenticationModule class detects the forms authentication cookie and authenticates the user. After successful authentication, the FormsAuthenticationModule class populates the current User property, which is exposed by the HttpContext object, with information about the authenticated user.

Forms Authentication in ASP.NET[^]

HttpContext.Current.User.Identity.Name gives the user name after successful authentication.
 
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