问候, 我为我的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)?
答案 0 :(得分:2)
您可以执行以下操作:
var userIdentity = HttpContext.Current.User.Identity;
var user = GetUser(userIdentity.Name, userIdentity.IsAuthenticated);
现在,您可以使用user
对象