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
Release: 2025-01-26 10:16:10
Original
477 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template