我試圖從web服務中存儲一整個關於用戶的信息。由於這是關於當前通過身份驗證的用戶的信息,我認爲將這些信息存儲在自定義IIdentity實現中是有意義的。MVC2 ::我如何*使用*自定義IIdentity類?
自定義MagicMembershipProvider.GetUser(string id, bool userIsOnline)
調用webservice並返回一個MagicMembershipUser
實例,其中包含所有填充的字段(部門,電話號碼和其他員工信息)。
自定義成員資格提供程序和自定義成員資格用戶都正常工作。
什麼和其中是把會員用戶信息到IPrincipal User
對象,它是在每個控制器可訪問的最佳方式?
我一直試圖圍繞MVC2應用程序中的IIdentity,IPrincipal和Role授權的安全程序流程大腦 - 但我在這裏真的很苦惱,可以使用一些指導。有關於部件的Internet Ton文章,但對整體而言並不多。
編輯
我最好的猜測,到目前爲止是分配HttpContext.Current.User
在FormsAuthenticationService
:
public void SignIn(string userName, bool createPersistentCookie)
{
if (String.IsNullOrEmpty(userName))
throw new ArgumentException("Value cannot be null or empty.", "userName");
try
{
FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
MagicMembershipUser magicUser = _provider.GetUser("", false)
as MagicMembershipUser;
MagicIdentity identity = new MagicIdentity(userName, magicUser);
GenericPrincipal principal = new GenericPrincipal(identity, null);
HttpContext.Current.User = principal;
}
catch (Exception)
{
throw;
}
}
我注意到_provider沒有實例 - 爲什麼? – 2011-01-21 18:40:09