How to get aspnet_Users.UserId for an anonymous user in ASP.NET membership?

I am trying to get an aspnet membership field UserIdfrom an anonymous user.

I have enabled anonymous authentication in web.config:

<anonymousIdentification enabled="true" />

I 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 table aspnetdb\aspnet_Usersfor anonymous users who have profile information.

Userid                                  PropertyNames   PropertyValuesString     
36139818-4245-45dd-99cb-2a721d43f9c5    Email:S:0:17:   me@example.com

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

Unable to use:

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

Request.AnonymousID is a different GUID, not 36139818-4245-45dd-99cb-2a721d43f9c5.

Is there any way to get this userid. I want to associate it with an incomplete activity for an anonymous user. Using a primary key is aspnet_Userspreferable to creating my own GUID (which I could do and store in my profile).

, .

+3
2

UserId :

string userId = Request.AnonymousID

+4

, MemberShip.GetUser() MembershipUser.

aspnetdb, , aspnet_Users ( ) - โ€‹โ€‹ aspnet_Membership, /.

( aspnet_Users) GUID UserName.

UserId , , .

UserId aspnet_Users, , UserId, "" SQL.

+2

Source: https://habr.com/ru/post/1721001/


All Articles