ASP.NET membership get UserId of anonymous user

☆樱花仙子☆ 提交于 2019-12-22 17:37:36

问题


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?


回答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.

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



来源:https://stackoverflow.com/questions/741893/asp-net-membership-get-userid-of-anonymous-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!