We help IT Professionals succeed at work.

How to populate an asp:textbox with current user?

Hello Experts.

I have a basic membership asp.net c# website (I used the web forms template provided in a Visual Studio 2012).  I have a text box (creator_txt) that I added to one my my forms (frm_case).  I would like to populate creator_txt with the userId of the currently logged-in user.  I'm not sure how to accomplish this so any suggestions would be greatly appreciated.

Thanks,
J
Comment
Watch Question

Fernando SotoRetired
Distinguished Expert 2017
Commented:
Hi ferguson_jerald;

Have you tried using something like this?

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Open in new window

Contract ERP Admin/Consultant
Commented:
If you're running on a server, you may get back "Network Service" with the above. Try:

creator_text.Text = System.Web.HttpContext.Current.User.Identity.Name;

Author

Commented:
Thank you for the help.  It was exactly what I needed.