ProviderInfo 对象中的匿名用户名应该是什么样子?
根据 Microsoft 的 ProfileInfo 定义 http://msdn.microsoft.com /en-us/library/system.web.profile.profileinfo.aspx,未经身份验证的 profileinfo 对象具有用户名;当然,这必须在给定会话中保留/引用配置文件信息(我假设它是基于会话的)。我猜这是一些指导或其他东西,但我看不到它是在哪里定义、创建、跟踪等的。有人能指出我正确的方向吗?
Per Microsoft's ProfileInfo definition http://msdn.microsoft.com/en-us/library/system.web.profile.profileinfo.aspx, an unauthenticated profileinfo object has a username; naturally this must be keyed off of to persist/ reference profile information in a given session (I am assuming it is session-based). I'm guessing this is some guid or something, but I don't see where this is defined, created, tracked, etc. Can someone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯...这个问题引起了我的兴趣,所以我决定做一些研究。
通过对文档进行一些挖掘,我首先实现配置文件提供程序 MSDN文章,我发现了以下内容:
因此,用户是否通过身份验证的确定通常是在更高级别上完成的。不管怎样,我查看了微软默认的SqlProfileProvider实现的代码(即
GetPropertyValues
方法实现),发现它调用了private void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
实际上有以下代码:因此,如果我们有一个未经身份验证的请求,则从以下位置获取用户 ID
HttpContext.Current.Request.AnonymousID
属性。通过 MSDN 搜索此属性显示以下页面: HttpRequest .AnonymousID 属性 (System.Web)。虽然它仍然没有描述生成此 ID 的确切算法,但它提供了有关如何根据需要覆盖此默认算法的信息。您所需要做的就是在 Web 应用程序中重载public void AnonymousIdentification_Creating(Object sender, AnonymousIdentificationEventArgs e)
方法。此页面还提供了有关如何在调用之间保留 AnonymousID 的一些信息(默认情况下,它存储在.ASPXANONYMOUS
cookie 中)。示例代码:
摘要: 我无法回答您关于默认情况下如何创建此 ID 的原始问题,但我认为最后一个代码片段足以让您使用您想要的任何算法覆盖它。
Well... The question interested me so I've decided to do some research.
A bit of digging in documentation lead me first to Implementing a Profile Provider MSDN article, where I've found the following:
So, the determination of whether user is authenticated or not is generally done on higher level. Anyway, I took a look at code of Microsoft's default SqlProfileProvider implementation (namely,
GetPropertyValues
method implementation) and found out that it calls methodprivate void GetPropertyValuesFromDatabase(string userName, SettingsPropertyValueCollection svc)
which actually has the following code:So, if we have a non-authenticated request then a user id is taken from
HttpContext.Current.Request.AnonymousID
property. Searching through MSDN for this property has revealed the following page: HttpRequest.AnonymousID property (System.Web). Although it still does not describe exact algorithm of generating this ID, but it provides information on how you can override this default algorithm if you want. All you need is to overloadpublic void AnonymousIdentification_Creating(Object sender, AnonymousIdentificationEventArgs e)
method in your web application. Also this page provides some information on how AnonymousID is persisted between calls (by default it's stored in.ASPXANONYMOUS
cookie).Example code:
Summary: I have not been able to answer your original question on HOW this ID is created by default but I think that last code snippet will be enough for you to override this with any algorithm you want.