3
我試圖使用HttpContext.Current.User
與我自己的類繼承IPrincipal
。我不完全確定爲什麼..如何將HttpContext.Current.User作爲mvc中的自定義主體c#
var lIdentity = new UserIdentity(lFormsTicket);
var lRoles = lAuthUser.Roles.Select(x => x.Role.ToString()).ToArray();
var lPrincipal = new GenericPrincipal(lIdentity, lRoles);
System.Web.HttpContext.Current.User = lIdentity;
我剛剛設置它後,它的作品。但是如果我在網站上做了另一個請求,它說它不能投射它。我在這裏錯過了什麼嗎?
這也不起作用。 (BO.Security.UserIdentity)User.Identity導致同樣的問題。 –
拋出錯誤在哪裏。同時顯示你的'BO.Security.UserIdentity'類,因爲我們需要知道它繼承了什麼。請注意,'GenericPrincipal.Identity' =>'獲取由當前System.Security.Principal.GenericPrincipal'表示的用戶的System.Security.Principal.GenericIdentity。 – Nkosi
錯誤正在被拋出無處不在我試圖將User.Identity作爲我的自定義用戶標識除了我設置用戶的方法(在登錄中)之外。 UserIdentity繼承自IIdentity –