Asp.net Membership Provider Guid userID

I need (I think) to get the current input user id so that I can update one of my tables that uses this user id as a foreign key. The problem is that the user ID in the database does not match this:

Guid currentUser = (Guid)Membership.GetUser().ProviderUserKey; currentUser.toString(); 

leads to dffaca0c-ae0b-8549-8073-1639985740be

then when I look in the database it is 0CCAFADF0BAE498580731639985740BE

Why are they different meanings? (I have only one user). I am using the oracle and provider database for asp.net, but should not make any difference.

+4
source share
4 answers

I believe that these are the same values, but the display order is different. Looking at 2 values:

 dffaca0c-ae0b-8549-8073-1639985740be 0CCAFADF-0BAE-4985-8073-1639985740BE 

The byte order for the first 3 segments has a different order:

 0CCA FADF => FADF 0CCA => DFFA CA0C == dffaca0c 0BAE => AE 0B == ae0b 4985 => 85 49 == 8549 

Like @ x0n's comments, this looks like a difference in content with Oracle. According to this description of the structure, the essence of the first 8 bytes depends on the system, and the finiteness of the last 8 bytes depends on.

+6
source

I had the same problem and I decided that this solved the problem:

  public static string TranslateOraceEndianUserID() { MembershipUser myObject = Membership.GetUser(); Guid g = new Guid(myObject.ProviderUserKey.ToString()); byte[] b = g.ToByteArray(); string UserID = BitConverter.ToString(b, 0).Replace("-", string.Empty); return UserID; } 
+3
source

Or maybe try using HttpContext.Curent.User to get the current user?

0
source

You can always use the Lowercase Username column to create a foreign key. He is always unique. This may not be the best option, but it is the easiest and works well. I used it in several projects.

0
source

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


All Articles