MembershipProvider用户ID

时间:2010-04-17 19:13:18

标签: asp.net-mvc asp.net-membership

问候, 我为我的asp.net mvc应用程序编写了一个自定义MembershipProvider。我得到如下用户:

public override MembershipUser GetUser(string username, bool userIsOnline)
    {
        using (CPersistanceManager pm = new CPersistanceManager())
        {
            pm.EnsureConnectionOpen();
            MembershipUser membershipUser = null;
            COperator oper = pm.OperatorRepository.Get(username);
            membershipUser = new MembershipUser(ApplicationName,
                                               oper.Username,
                                               oper.ROWGUID,
                                               oper.Email,
                                               string.Empty,
                                               string.Empty,
                                               oper.IsActive,
                                               false,
                                               DateTime.Today,
                                               DateTime.Today,
                                               DateTime.Today,
                                               DateTime.Today,
                                               DateTime.Today
                                                );
            return membershipUser;
        }
    }

如何在任何控制器中检索已记录的用户ID(rowguid)?

1 个答案:

答案 0 :(得分:2)

您可以执行以下操作:

var userIdentity = HttpContext.Current.User.Identity;
var user = GetUser(userIdentity.Name, userIdentity.IsAuthenticated);

现在,您可以使用user对象

执行任何操作