我使用IIdentity
接口获取当前userid
和username
。以身份获得当前用户电子邮件
所以实现以下方法:
private static IIdentity GetIdentity()
{
if (HttpContext.Current != null && HttpContext.Current.User != null)
{
return HttpContext.Current.User.Identity;
}
return ClaimsPrincipal.Current != null ? ClaimsPrincipal.Current.Identity : null;
}
并添加以下代码:我的IoC容器[structuremap]
_.For<IIdentity>().Use(() => GetIdentity());
。
使用
this._identity.GetUserId();
this._identity.GetUserName();
this._identity.IsAuthenticated
现在我想要实现GetEmailAdress
方法,如何做到这一点?
例
this._identity.GetEmailAdress();
使用时this._identity.GetUserName();
没有得到用户名形式数据库。
电子邮件是从用户的配置文件,而不是他的身份数据。您需要获取当前用户的配置文件对象,然后检索他的电子邮件。 –