如何获取 ASP.NET 成员身份中的匿名用户的 aspnet_Users.UserId?
我正在尝试从匿名用户获取 aspnet 成员资格 UserId
字段。
我在 web.config 中启用了匿名识别:
<anonymousIdentification enabled="true" />
我还创建了一个配置文件:
<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>
我在 aspnetdb\aspnet_Users
表中看到已设置配置文件信息的匿名用户的数据。
Userid PropertyNames PropertyValuesString
36139818-4245-45dd-99cb-2a721d43f9c5 Email:S:0:17: [email protected]
我只需要找到如何获取“Userid”值。
无法使用:
Membership.Provider.GetUser(Request.AnonymousID, false);
Request.AnonymousID 是不同的 GUID,且不等于 36139818-4245-45dd-99cb-2a721d43f9c5。
有什么办法可以获取这个Userid吗?我想将其与匿名用户的不完整活动关联起来。使用 aspnet_Users
的主键比创建自己的 GUID(我可以创建并存储在配置文件中)更好。
这基本上是这个问题的骗局,但问题是从未真正回答过。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过以下方式获取匿名用户的 UserId:
string userId = Request.AnonymousID
You can get the UserId for an anonymous user with this:
string userId = Request.AnonymousID
好的,所以
MemberShip.GetUser()
返回一个MembershipUser
类型的对象。深入研究
aspnetdb
数据库中的表,似乎虽然在aspnet_Users
中为所有用户(甚至是匿名用户)创建了一行,但不会在aspnet_Membership中创建一行,除非用户实际上已通过身份验证/注册。但是,匿名用户配置文件(aspnet_Users 表)会被赋予 GUID,而不是
UserName
。我仍然没有找到访问匿名用户的
UserId
属性的方法 - 但我意识到用户名实际上是更有用的密钥。UserId
字段也存在于aspnet_Users
表中,因此如果您确实需要唯一的 UserId 字段,那么您可以通过“手动”SQL 查找来获取它。OK, so
MemberShip.GetUser()
returns an object of typeMembershipUser
.Delving more into the tables in the
aspnetdb
database it seems that although a row is created inaspnet_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 inaspnet_Users
table also, so if you really need the unique UserId field then you can get it with a 'manual' SQL lookup.