ASP.NET 会员资格获取匿名用户的 UserId
我正在开发一个使用 .net 成员资格的现有项目。 我们希望扩展该项目以允许匿名用户,但我们似乎遇到了障碍,因为我们使用 aspnet_Users 表的 UserId 作为许多数据库表中的外键。
以下调用返回 null,因为 aspnet_Membership 表中没有匿名用户的记录
Membership.Provider.GetUser(Request.AnonymousID, false);
有没有办法通过标准 API 获取匿名用户的 UserId? 或者我必须编写一个可以做到这一点的扩展吗?
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.
The following call returns null as there is no record in the aspnet_Membership table for anonymous users
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,这是关于访问的。 如果您的网站有不需要访问的模块或页面。 您需要首先在 aspnet users 表中创建一个用户。 可能是该匿名用户未正确创建,导致空值。
此外,如果您想跟踪这些匿名用户,则必须在您的个人资料提供程序配置中将allowanonymous 设置为true。
请参阅这篇文章以获取更多帮助
http://www.odetocode.com/Articles/440.aspx
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.
Additionally if you want to track these anonymous users, you have to set allowanonymous to true in your profile provider configuration.
See this article for more help
http://www.odetocode.com/Articles/440.aspx