我使用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();
沒有得到用戶名形式數據庫。
電子郵件是從用戶的配置文件,而不是他的身份數據。您需要獲取當前用戶的配置文件對象,然後檢索他的電子郵件。 –