HttpRequest.AnonymousID プロパティ
アセンブリ: System.Web (system.web.dll 内)

現在の匿名ユーザーの ID を表す文字列。

AnonymousId プロパティは、認証を受けていないユーザーに対し、長時間存続する一意の ID を割り当てます。これを使用して、ユーザーを追跡したり、データを Session オブジェクトに保存せずにプロファイル プロパティをそのユーザーに割り当てたりできます。既定では、AnonymousId は Cookie を使用して追跡されます。しかし、匿名 ID の構成セクションの Cookieless 属性を UseUri、UseDeviceProfile、または AutoDetect のいずれかの値に設定すると、URI を使用するように設定できます。Cookie を利用する必要がなくなった場合、たとえば、匿名ユーザーが認証された場合などは、明示的に削除する必要があります。
匿名 ID は、認証されていない実体を識別する必要がある場合、および承認が要求される場合に使用します。詳細については、「anonymousIdentification 要素 (ASP.NET 設定スキーマ)」を参照してください。

Global.asax ファイルの AnonymousIdentification_OnCreate イベントにアクセスして AnonymousId プロパティを使用する方法のコード例を次に示します。この例は、2 つの部分で構成されます。
このコード例の最初の部分では、Global.asax ファイルの AnonymousIdentification_OnCreate イベントにアクセスして AnonymousId プロパティを使用する方法を示します。AnonymousIdentification_OnCreate イベントは、新しい匿名 ID が作成されるたびに発生します。
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If (Application("UserCount") IsNot Nothing) Then lblUserCount.Text = Application("UserCount").ToString() lblCurrentUser.Text = Request.AnonymousID End If End Sub </script> <html > <head id="Head1" runat="server"> <title>AnonymousID Example</title> </head> <body> <form id="form1" runat="server"> <div> Number of users: <asp:Label ID="lblUserCount" Runat="server"></asp:Label><br /> Current user: <asp:Label ID="lblCurrentUser" Runat="server"></asp:Label><br /> </div> </form> </body> </html>
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> void Page_Load(object sender, EventArgs e) { if (Application["UserCount"] != null) { lblUserCount.Text = Application["UserCount"].ToString(); lblCurrentUser.Text = Request.AnonymousID; } } </script> <html > <head runat="server"> <title>AnonymousID Example</title> </head> <body> <form id="form1" runat="server"> <div> Number of users: <asp:Label ID="lblUserCount" Runat="server"></asp:Label><br /> Current user: <asp:Label ID="lblCurrentUser" Runat="server"></asp:Label><br /> </div> </form> </body> </html>
コード例の 2 番目の部分では、前の例の AnonymousIdentification_OnCreate イベントによって作成された新しい AnonymousId を表示する方法を示します。
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) 'Initialize user count property Application("UserCount") = 0 End Sub Sub AnonymousIdentification_OnCreate(ByVal sender As Object, ByVal e As AnonymousIdentificationEventArgs) ' 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 End Sub
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; }

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


HttpRequest クラス
HttpRequest メンバ
System.Web 名前空間
IsAuthenticated
その他の技術情報
anonymousIdentification 要素 (ASP.NET 設定スキーマ)
- HttpRequest.AnonymousID プロパティのページへのリンク