8

在MVC中這兩個有什麼區別?ClaimsPrincipal.Current與HttpContext.Current.User?

他們看起來相同,他們甚至返回相同的類型/類System.Web.Security.RolePrincipal,但有微妙之處。

例如,當所謂的反對通過ClaimsPrincipal.Current

cp.FindFirst(ClaimTypes.Name); //{"Unable to connect to SQL Server database."} <--HUH!? 
cp.Claims; //{"Value cannot be null.\r\nParameter name: username"} 

上述工程所產生的實例下面的代碼拋出的各種錯誤時,CP是這個:

var cp = System.Web.HttpContext.Current.User 

當向下鑽取通過快速監視我的私有成員可以看到他們都有相同的索賠字典。然而,無論出於何種原因,公共財產吹來的時候被稱爲ClaimsPrincipal.Current

幫助 - 爲什麼是這個!這真讓我抓狂。

=============編輯==================

它必須是差不多的時間去睡覺。

IPrincipal支持多種身份。它需要某種商店。 IIdentity返回ClaimsIdentity的一個實例,不需要商店。

我只是鑽出了錯誤的屬性。他們兩個的形狀幾乎相同,即。相同的屬性和方法,我弄糊塗了。

回答

相關問題