gpt4 book ai didi

c# - User.Identity.GetUserId 是缓存还是每次都从数据库中获取?

转载 作者:太空狗 更新时间:2023-10-29 21:08:31 26 4
gpt4 key购买 nike

我正在使用 ASP.Net MVC 5 并且我在我的代码中调用了这一行

string userId = User.Identity.GetUserId();

ASP.NET MVC 是在每次调用时从表中获取它,还是缓存它?

最佳答案

查看 Microsoft.AspNet.Identity.Core.dll 的反编译源,您可以看到它从当前身份的声明中检索用户 ID。所以它不会从数据库中获取此信息。

public static string GetUserId(this IIdentity identity)
{
if (identity == null)
throw new ArgumentNullException("identity");
ClaimsIdentity identity1 = identity as ClaimsIdentity;
if (identity1 != null)
return IdentityExtensions.FindFirstValue(identity1, "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");
return (string) null;
}

关于c# - User.Identity.GetUserId 是缓存还是每次都从数据库中获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28520171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com