簡體   English   中英

如何獲取windows用戶名

[英]How to get windows username

我正在嘗試在 aspx 頁面上獲取 Windows 用戶名。

我嘗試了以下方法:

<% System.Threading.Thread.CurrentPrincipal = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()) %>
<%= System.Threading.Thread.CurrentPrincipal.Identity.Name %>

但所做的只是給我IIS APPPOOL/SBalance - 這不是 Windows 用戶名!

但是,如果我添加以下服務器控件:

<asp:LoginName ID="LoginName1" runat="server" />

這確實成功地預先填充了我的域和用戶名。

那么如何在不使用登錄控件的情況下在 aspx 頁面上將域/用戶名作為字符串獲取?

謝謝

如果您使用 Windows 身份驗證,您可以通過User.Identity.Name獲取用戶名

string windowsLogin = Page.User.Identity.Name;

您需要在 web.config 中啟用模擬

<identity impersonate="true" />

那么你需要在 IIS 中啟用 windows 模擬並禁用匿名身份驗證

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM