Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current Windows Login Name in C# Web APP?

Tags:

c#

How can I get the user name of Windows Login? I used these methods:

  • Environment.UserName
  • WindowsIdentity.GetCurrent().Name;

But, when I PUT this inside IIS server, it takes the name of the server, not my machine.

like image 933
soamazing Avatar asked May 15 '12 20:05

soamazing


People also ask

How do I get the current username in .NET using C #?

GetCurrent(). Name; Returns: NetworkName\Username.

What is my PC account name?

Click on the Start button. Right-click on Computer. Select Properties. Under Computer name, domain, and workgroup settings you will find the computer name listed.


1 Answers

Try Page.User.Identity.Name. This should be what you're looking for. This property is derived from HttpContext and represents the logged in user security information for the current HTTP request.

If the result is null, then I would suspect that the IIS settings is not configured properly. Try the advice in the following links:

http://forums.asp.net/t/1689878.aspx/1
HttpContext.Current.User.Identity.Name is Empty

like image 67
code4life Avatar answered Oct 18 '22 02:10

code4life