views:

81

answers:

1

Greetings, I wrote a custom MembershipProvider for my asp.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?

+1  A: 

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

Mahesh Velaga
yes but then, I will have to get data from db each time.
niao
You can save the user objetc in session or keep it in the HttpContext for the request.
uvita
doesn't make much sense to sometimes using Username as id and sometimes Rowguid. Better decide on which one you want to use as an user identifier.
mare
well.. I would like to always use ROWGUID
niao