Home >Backend Development >C++ >How to Get the Current Username in C# .NET?

How to Get the Current Username in C# .NET?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-26 10:16:10512browse

How to Get the Current Username in C# .NET?

Use C# .NET to get the current username

.NET framework

Naming space provides a method of accessing security information, including the identity of the current user. To obtain the current username, you can use the

class, as shown below: System.Security.Principal WindowsIdentity code:

Explanation:

<code class="language-csharp">string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;</code>

Use the method to obtain the current Windows identity.

Access The
    attribute of the object to obtain the username.
  1. WindowsIdentity.GetCurrent()
  2. Example:
  3. WindowsIdentity Name
  4. Output:

The above is the detailed content of How to Get the Current Username in C# .NET?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn