我有一个关于IIdentity身份的问题,通常在web应用程序中,你可以这样说:
HttpContext.Current.User.Identity.它有几个属性,你可以很容易地检索到,非常方便。
所以我有两个问题:
1)我正在使用ASP.NET身份(而不是成员),但是当我尝试扩展HttpContext.Current.User.Identity时
public static int GetUserAge(this IIdentity identity){}要导入:我必须使用IIdentity标识,使用System.Security.Principal;,但它是否与Microsoft.AspNet.Identity在同一个包中?
2)默认情况下,User.Identity.Name / User.Identity.Id、/ User.Identity.GerUserId()等方法和属性是如何实现的?实现是否每次都要到数据库中去检索它?或者它在会话中保存,或者...?
因为我想创建一个扩展,并且工作方式与默认方式大致相同。
发布于 2014-01-14 06:25:13
因此,AspNet.Identity只添加了扩展方法,这些扩展方法提供了语法糖来隐藏将IIdentity转换为ClaimsIdentity,并将两个声明类型映射到助手方法getter。
GetUserName() => ClaimTypes.Name
GetUserId() => ClaimTypes.NameIdentifier.https://stackoverflow.com/questions/21098332
复制相似问题