ASP.NET成员资格获得匿名用户的UserId

时间:2021-11-13 03:38:30

I have an existing project that i'm working on that uses .net membership. We want to expand the project to allow anonymous users but we seem to have hit a snag as we use the UserId of the aspnet_Users table as a foreign key in many of our database tables.

我有一个正在使用.net成员资格的现有项目。我们希望扩展项目以允许匿名用户,但我们似乎遇到了麻烦,因为我们在许多数据库表中使用aspnet_Users表的UserId作为外键。

The following call returns null as there is no record in the aspnet_Membership table for anonymous users

以下调用返回null,因为匿名用户的aspnet_Membership表中没有记录

Membership.Provider.GetUser(Request.AnonymousID, false);

Is there any way to get the UserId of an anonymous user through the standard API's? or will I have to write an extension that can do it?

有没有办法通过标准API获取匿名用户的UserId?或者我必须写一个可以做到的扩展吗?

1 个解决方案

#1


As far as I know it is about access. If your web site has modules or pages that do not need access. You need to create a user first in the aspnet users table. It could be that this anonymous user is not created correctly leading to the null value.

据我所知,这是关于访问。如果您的网站包含不需要访问的模块或页面。您需要首先在aspnet用户表中创建用户。可能是未正确创建此匿名用户导致null值。

Additionally if you want to track these anonymous users, you have to set allowanonymous to true in your profile provider configuration.

此外,如果要跟踪这些匿名用户,则必须在配置文件提供程序配置中将allowanonymous设置为true。

See this article for more help http://www.odetocode.com/Articles/440.aspx

有关更多帮助,请参阅此文章http://www.odetocode.com/Articles/440.aspx

#1


As far as I know it is about access. If your web site has modules or pages that do not need access. You need to create a user first in the aspnet users table. It could be that this anonymous user is not created correctly leading to the null value.

据我所知,这是关于访问。如果您的网站包含不需要访问的模块或页面。您需要首先在aspnet用户表中创建用户。可能是未正确创建此匿名用户导致null值。

Additionally if you want to track these anonymous users, you have to set allowanonymous to true in your profile provider configuration.

此外,如果要跟踪这些匿名用户,则必须在配置文件提供程序配置中将allowanonymous设置为true。

See this article for more help http://www.odetocode.com/Articles/440.aspx

有关更多帮助,请参阅此文章http://www.odetocode.com/Articles/440.aspx