views:

639

answers:

2

I am trying to get the aspnet membership UserId field from an anonymous user.

I have enabled anonymous identification in web.config :

<anonymousIdentification enabled="true" />

I have also created a profile:

<profile>

  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
         connectionStringName="ApplicationServices" 
         applicationName="/" />
  </providers>

  <properties>
    <add name="Email" type="System.String" allowAnonymous="true"/>
    <add name="SomethingElse" type="System.Int32" allowAnonymous="true"/>
  </properties>

</profile>

I see data in my aspnetdb\aspnet_Users table for anonymous users that have had profile information set.

Userid                                  PropertyNames   PropertyValuesString     
36139818-4245-45dd-99cb-2a721d43f9c5    Email:S:0:17: [email protected]

I just need to find how to get the 'Userid' value.

It is not possible to use :

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

The Request.AnonymousID is a different GUID and not equal to 36139818-4245-45dd-99cb-2a721d43f9c5.

Is there any way to get this Userid. I want to associate it with incomplete activity for an anonymous user. Using the primary key of aspnet_Users is preferable to having to create my own GUID (which I could do and store in the profile).

This is basically a dupe of this question but the question was never actually answered.

+2  A: 

OK, so MemberShip.GetUser() returns an object of type MembershipUser.

Delving more into the tables in the aspnetdb database it seems that although a row is created in aspnet_Users for all users (even anonymous ones) - a row is NOT created in aspnet_Membership unless the useris actually authenticated/registered.

But, an anonymous user profile (aspnet_Users table ) is given a GUID instead of a UserName.

I still haven't found a way to access the UserId property of an anonymous user - but I've realized that really the username is the more useful key anyway.

The UserId field is present in aspnet_Users table also, so if you really need the unique UserId field then you can get it with a 'manual' SQL lookup.

Simon_Weaver
+1  A: 

You can get the UserId for an anonymous user with this:

string userId = Request.AnonymousID

GDB
wierd. not sure how i missed that. thx
Simon_Weaver