asp.net-identity – IIdentity.Name与IIdentity.GetUserName()
发布时间:2020-12-16 04:38:29 所属栏目:asp.Net 来源:网络整理
导读:扩展方法位于Microsoft.AspNet.Identity中.那有什么区别?这些2什么时候会返回不同的值? var idName = User.Identity.Name;var idGetName = User.Identity.GetUserName(); 解决方法 扩展方法的实现是这样的; public static string GetUserName(this IIdenti
扩展方法位于Microsoft.AspNet.Identity中.那有什么区别?这些2什么时候会返回不同的值?
var idName = User.Identity.Name; var idGetName = User.Identity.GetUserName(); 解决方法
扩展方法的实现是这样的;
public static string GetUserName(this IIdentity identity) { if (identity == null) { throw new ArgumentNullException("identity"); } ClaimsIdentity claimsIdentity = identity as ClaimsIdentity; if (claimsIdentity == null) { return null; } return claimsIdentity.FindFirstValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name"); } IIdentity.Name和IdentityExtensions.GetUserName()之间唯一明显的返回值差异是,如果底层IIdentity实现不是ClaimsIdentity,则GetUserName()始终返回null,而Name属性将返回底层IIdentity实现返回的任何内容. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ADO.NET实用经验 转载
- asp.net-mvc – ASP.net MVC:在RenderAction中获取“Main-
- .net-core – 存储Azure Vault客户端ID和客户端密钥
- asp.net-mvc – 验证嵌套模型
- asp.net – ‘txtName’未声明 由于其保护等级可能无法访问
- asp.net-mvc – 设计ASP.NET MVC 3站点以支持客户特定的视图
- asp.net-mvc – 如何使用ViewBag创建一个下拉列表?
- asp.net-web-api – WebAPI 2属性路由启用会话状态
- asp.net-mvc-3 – 定义WebActivator.PreApplicationStartMe
- ASP.NET – 在GridViewRowEventArgs Row.Cells.Item中使用列
推荐文章
站长推荐
- asp.net-mvc – ASP.NET Web API比ASP.NET MVC有
- nTier应用程序中的.Net会员资格
- asp.net core视图中使用Json序列化模型
- 即使模型无效,ASP.NET MVC“Ajax.BeginForm”也执
- asp.net – 将Always Encrypted Certificate放在
- asp.net – 抽象通用ODataController类导致“没有
- asp.net-mvc – 使用cshtml页面的angularjs不是带
- C#中try catch中throw ex和throw方式抛出异常有何
- asp.net-mvc-4 – 使用从控制器操作返回的JSON.N
- ASP.NET – ActionResult参数在传递字符串时总是
热点阅读