开发者

MembershipProvider user id

Greetings, I wrote a custom MembershipProvider for my as开发者_如何学Gop.net mvc application. I get the user as follows:

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;
        }
    }

how can I then retrieve logged user id (rowguid) in any controller?


You can do something like the following:

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

Now, you can do whatever you want with the user object

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜