2015-01-15 30 views
0

我有一個C#asp.net web應用程序,我需要獲得當前登錄用戶(的Windows authenticaion - 活動目錄)入門當前登錄的用戶從AD(而不是NT AUTHORITY/NETWORK SERVICE)

我但是當我使用「System.Security.Principal.WindowsIdentity.GetCurrent()」我沒有得到我自己的用戶憑證,但NT授權/網絡服務。

我試過讓iis使用我的帳戶來存儲應用程序池(僅用於測試),但是這隻會讓您感到厭倦。

任何想法我能做些什麼來獲得我自己的用戶憑據?

+0

使用'HttpContext.Current.User.Identity' – Joe 2015-01-15 17:22:03

回答

0

System.Security.Principal.WindowsIdentity.GetCurrent()返回運行該Web應用程序的帳戶的身份。

HttpContext.Current.User.Identity返回登錄用戶的身份。經常when you're in a page or controller,你可以做User.Identity。如有疑問,請閱讀文檔!

+0

在這種情況下,它是一個Sitecore的網站和HttpContext.Current.User.Identity給我{} Sitecore.Security.Principal.SitecoreIdentity而不是/ 在sitecoreIdentity內部是一個用戶,但是這是當前在sitecore extranet/anonymous登錄的用戶 – Timon 2015-01-16 08:11:06

+0

@Timon'.Name'屬性包含用戶名。根據[這篇博客文章](https://briancaos.wordpress.com/2012/11/01/sitecore-users-and-c/),這是預期的。當用戶未登錄時,他們將擁有「extranet/anonymous」帳戶。但是一旦他們登錄,聽起來就像你會看到他們的實際域名和用戶名。 – mason 2015-01-16 14:21:47

相關問題