【发布时间】:2011-06-12 19:52:50
【问题描述】:
我正在尝试从网络服务中存储有关用户的大量信息。由于这是有关当前经过身份验证的用户的信息,因此我认为将这些信息存储在自定义 IIdentity 实现中是有意义的。
自定义 MagicMembershipProvider.GetUser(string id, bool userIsOnline) 调用 Web 服务并返回一个 MagicMembershipUser 实例,其中填充了所有字段(部门、电话号码、其他员工信息)。
自定义会员提供者和自定义会员用户都可以正常工作。
什么和在哪里是将会员用户信息放入每个控制器都可以访问的IPrincipal User对象的最佳方式?
我一直试图在 MVC2 应用程序中使用 IIdentity、IPrincipal 和 Role 授权来围绕安全程序流进行思考——但我在这里真的很挣扎,可以使用一些指导。互联网上有大量关于部分的文章,但关于整体的文章不多。
编辑
到目前为止,我最好的猜测是在FormsAuthenticationService 中分配HttpContext.Current.User:
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;
}
}
【问题讨论】:
标签: security asp.net-mvc-2 authorization iprincipal iidentity