简体   繁体   English

asp.net会员提供者Guid userID

[英]asp.net membership provider Guid userID

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. 我需要(我认为)获取当前登录的userID,以便我可以更新一个使用此userID作为外键的表。 The problem is that the userID in the database does not match with this: 问题是数据库中的userID与此不匹配:

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

results in dffaca0c-ae0b-8549-8073-1639985740be 结果在dffaca0c-ae0b-8549-8073-1639985740be中

whereas when I look in the database, it is 0CCAFADF0BAE498580731639985740BE 而当我查看数据库时,它是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. 我正在使用asp.net的oracle数据库和提供程序,但不应该有任何区别。

I believe these are the same values, but the display order is different. 我相信这些是相同的值,但显示顺序是不同的。 Looking at the 2 values: 看看2个值:

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

The ordering of bytes for the first 3 segments is of a different order: 前3个段的字节顺序顺序不同:

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. 正如@ x0n评论,这看起来与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. 根据结构的这种描述 ,前8个字节的字节序是依赖于系统的,而最后8个字节的字节序特别是大端字节。

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;
    }

或者也可以尝试使用HttpContext.Curent.User来获取当前用户?

You could always use the Lower Case User Name column to create the foreign Key. 您始终可以使用小写用户名列来创建外键。 It is always unique. 它总是独一无二的。 Maybe not the best option but it is the simplest and works well. 也许不是最好的选择,但它是最简单的,效果很好。 I have used it in several projects. 我在几个项目中使用过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM