Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net membership provider Guid userID

Tags:

asp.net

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

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

results in dffaca0c-ae0b-8549-8073-1639985740be

whereas when I look in the database, it is 0CCAFADF0BAE498580731639985740BE

Why are they different values? (I only have one user). I am using an oracle database and provider for asp.net, but shouldn't make any difference.

like image 280
BobTurbo Avatar asked Jan 21 '23 03:01

BobTurbo


2 Answers

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

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

The ordering of bytes for the first 3 segments is of a different order:

0CCA FADF => FADF 0CCA => DFFA CA0C == dffaca0c

0BAE => AE 0B == ae0b

4985 => 85 49 == 8549

As @x0n comments, this looks like a difference in endianness with Oracle. According the this description of the structure, the endianness of the first 8 bytes is system dependent, while the endianness of the last 8 bytes is specifically big endian.

like image 182
Jeff Ogata Avatar answered Jan 22 '23 18:01

Jeff Ogata


I had the same issue and came up with this which resolved the issue:

 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;
    }
like image 20
Norm Avatar answered Jan 22 '23 17:01

Norm