HttpRequest.AnonymousID 属性
获取该用户的匿名标识符(如果存在)。
命名空间: System.Web
程序集: System.Web(在 System.Web.dll 中)
备注 AnonymousId()()() 属性将一个长久的唯一标识符分配给一个未经身份验证的用户,该标识符可用于跟踪用户或将配置文件属性分配给该用户,而无需将数据存储在 Session 对象中。默认情况下,使用 Cookie 来跟踪 AnonymousId()()() 属性,但是,当匿名标识配置节中的 Cookieless 属性设置为 UseUri、UseDeviceProfile 或 AutoDetect 值时,AnonymousId()()() 也可以设置为使用 URI。如果您不再需要该 Cookie 起作用(例如,在对一个匿名用户进行身份验证时),则必须显式清除它。
在需要标识未经身份验证的实体时,以及在要求进行身份验证时,使用匿名标识。有关更多信息,请参见 anonymousIdentification 元素(ASP.NET 设置架构)
示例 下面的代码示例演示如何通过访问 Global.asax 文件中的 AnonymousIdentification_OnCreate 事件来使用 AnonymousId()()() 属性。此示例包括两个部分:
Web 窗体页。
处理 AnonymousIdentification_OnCreate 事件的方法。
代码示例的第一部分说明:如何通过访问 Global.asax 文件中 AnonymousIdentification_OnCreate 事件来使用 AnonymousId()()() 属性。每当创建新的匿名 ID 时都会引发 AnonymousIdentification_OnCreate 事件。
代码示例的第二部分说明:如何显示由前一个示例中的 AnonymousIdentification_OnCreate 事件创建的新 AnonymousId()()()。
void Application_Start(Object sender, EventArgs e)
{
// Initialize user count property
Application["UserCount"] = 0;
}
public void AnonymousIdentification_OnCreate(Object sender, AnonymousIdentificationEventArgs e)
{
// Change the anonymous id
e.AnonymousID = "mysite.com_Anonymous_User_" + DateTime.Now.Ticks;
// Increment count of unique anonymous users
Application["UserCount"] = Int32.Parse(Application["UserCount"].ToString()) + 1;
}






}
}
浙公网安备 33010602011771号