ASP.NET成员:哪里是当前用户ID存储在哪里? [英] ASP.NET Membership: Where is Current User ID Stored?

查看:119
本文介绍了ASP.NET成员:哪里是当前用户ID存储在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ASP.NET成员资格,如果我想获得当前用户,我可以调用信息 MembershipUser.GetUser()

Using ASP.NET membership, if I want to get information for the current user, I can call MembershipUser.GetUser()

因此​​,不知何故系统必须知道当前用户的ID。

So, somehow the system must know the ID of the current user.

如果这是正确的,我要的是当前用户的ID,有没有办法得到它,而不从数据库返回的所有用户信息?

If this is correct, and all I want is the ID of the current user, is there a way to get it without returning all the user information from the database?

我知道我可以使用 User.Identity.Name 获取当前用户的用户名,但我需要的ID。

I know I can get the username of the current user using User.Identity.Name, but I need the ID.

推荐答案

寻找到这进一步后,似乎ASP.NET成员API不会跟踪用户ID毕竟。它必须跟踪只是用户名( User.Identity.Name )。不是必需的ID,因为 Membership.GetUser()可以找到从ID的用户的的用户名。

After looking into this further, it seems that the ASP.NET Membership API does not track the user ID after all. It must track just the user name (User.Identity.Name). The ID is not required because Membership.GetUser() can find a user from an ID or user name.

其实, Membership.GetUser()必须简单地转换为 Membership.GetUser(User.Identity.Name)。因为它可以从用户获得名当前用户,不再有任何理由假定当前用户ID的任何地方缓存。

In fact, Membership.GetUser() must simply translate to Membership.GetUser(User.Identity.Name). Since it can obtain the current user from the user name, there is no longer any reason to assume that the current user ID is cached anywhere.

所以它出现在ID未加载到内存中,并获得标识的唯一方法是从加载数据库中的数据(这意味着使用ASP.NET成员API时加载整个用户记录)。

So it appears the ID is not loaded into memory, and the only way to obtain the ID is to load the data from the database (which means loading the entire user record when using the ASP.NET Membership API).

这篇关于ASP.NET成员:哪里是当前用户ID存储在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆