ASP.NET membership get UserId of anonymous user

2019-05-23 15:43发布

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条回答
放荡不羁爱自由
2楼-- · 2019-05-23 15:50

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

查看更多
登录 后发表回答