[英]How to get windows username
我們希望將應用程序托管在IIS中。 我們的應用程序將由Intranet用戶使用。
我們的主要要求是內部網用戶不應使用Windows提示符,因此我們沒有使用Windows身份驗證。 我們已使用具有活動目錄授權的表單身份驗證。 但是,然后我們沒有登錄到用戶名。(已登錄計算機的Windows用戶名)
第一種方法 -諸如“ System.Security.Principal.WindowsIdentity.GetCurrent().Name
”之類的代碼-在IIS中托管時不提供用戶名。
第二種方法-以下代碼通過Visual Studio為我提供了用戶名
RegistryKey processor_key = Registry.CurrentUser.OpenSubKey(@"Volatile Environment");
if (processor_key != null)
{
if (processor_key.GetValue("USERNAME") != null)
{
Console.WriteLine("Language: {0}", processor_key.GetValue("USERNAME").ToString());
string username = processor_key.GetValue("USERNAME").ToString();
txtUsername.Text = username;
}
}
但是當我在IIS中托管此站點時。 我沒有得到用戶名。
在不使用Windows身份驗證的情況下,有沒有辦法在IIS中獲取計算機用戶名?
請指導。
從MVC控制器(實際上是從System.Web.Mvc.Controller
類繼承)中,可以訪問在基礎Controller
定義的User
對象:
string username = this.User.Identity.Name;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.