OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How do I get the currently loggedin Windows account from an ASP.NET page?

  • Thread starter Thread starter StackTrace
  • Start date Start date
S

StackTrace

Guest
I have an ASP.NET 3.5 application that uses ASP.NET forms authentication. I want to be able to get the Windows user name currently logged into the computer (NOT logged into the ASP.NET application, but into Windows) when data is edited in a page.

If I use Context.User.Identity.Name.Tostring(), I get the user name logged into the ASP.NET application, but I need the Windows account name.

Code:
System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring()

Also, it only works when I run the website from Visual Studio, but after deploying to IIS it returns NT AUTHORITY\SYSTEM.
<p>I have an ASP.NET 3.5 application that uses ASP.NET forms authentication. I want to be able to get the Windows user name currently logged into the computer (NOT logged into the ASP.NET application, but into Windows) when data is edited in a page.</p>

<p>If I use <code>Context.User.Identity.Name.Tostring()</code>, I get the user name logged into the ASP.NET application, but I need the Windows account name.</p>

<pre><code>System.Security.Principal.WindowsIdentity.GetCurrent().Name.Tostring()
</code></pre>

<p>Also, it only works when I run the website from Visual Studio, but after deploying to IIS it returns <strong>NT AUTHORITY\SYSTEM</strong>.</p>
Continue reading...
 
Top