在C#中,您可以使用以下方法找到用户名/身份:
using System.Security.Principal;
WindowsIdentity identity = WindowsIdentity.GetCurrent();
string username = identity.Name;
string username = Environment.GetEnvironmentVariable("USERNAME");
using System.DirectoryServices.AccountManagement;
PrincipalContext context = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(context, "username");
string username = user.Name;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
HttpContext httpContext = HttpContext.Current;
string username = httpContext.User.Identity.Name;
请注意,这些方法可能需要根据您的应用程序和环境进行调整。在某些情况下,您可能需要使用其他库或API来获取用户名/身份。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云