Share via


HttpRequest.AnonymousID 속성

정의

사용자의 익명 ID를 가져옵니다(있는 경우).

public:
 property System::String ^ AnonymousID { System::String ^ get(); };
public string AnonymousID { get; }
member this.AnonymousID : string
Public ReadOnly Property AnonymousID As String

속성 값

현재 익명 사용자 ID를 나타내는 문자열입니다.

예제

다음 예제에서는 사용 AnonymousID 하는 방법에 설명 합니다 Global.asax 파일에서 이벤트를 처리 하 Creating 여 속성입니다. 이 예제에는 두 부분이 있습니다.

  • 이벤트를 처리하는 Global.asax 파일의 Creating 메서드입니다.

  • Web Forms 페이지입니다.

코드 예제의 첫 번째 부분은 Global.asax 파일에서 이벤트를 처리하여 Creating 속성을 설정하는 AnonymousID 방법을 보여줍니다. 명명 AnonymousIdentification_Creating 된 메서드는 익명 ID를 AnonymousID 만들 때 속성을 설정합니다.

void Application_Start(Object sender, EventArgs e)
    {
        // Initialize user count property
        Application["UserCount"] = 0;
    }
    
public void AnonymousIdentification_Creating(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;
}
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

    'Initialize user count property
    Application("UserCount") = 0

End Sub

Sub AnonymousIdentification_Creating(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

코드 예제의 두 번째 부분에서는 앞의 예제에서 이벤트 처리기에서 만든 AnonymousIdentification_CreatingAnonymousID 를 표시하는 방법을 보여줍니다.

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<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>
<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<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>

설명

속성은 AnonymousID 사용자를 추적하거나 개체에 데이터를 Session 저장하지 않고 해당 사용자에게 프로필 속성을 할당하는 데 사용할 수 있는 인증되지 않은 사용자에게 수명이 긴 고유 식별자를 할당합니다. 기본적으로 AnonymousID 속성은 쿠키를 사용하여 추적되지만 익명 식별 구성 섹션의 Cookieless 특성이 , UseDeviceProfile또는 AutoDetect 값으로 설정된 경우 URI를 UseUri사용하도록 설정할 수 있습니다. 익명 사용자가 인증되는 경우와 같이 쿠키를 더 이상 사용할 수 없게 하려면 쿠키를 명시적으로 지워야 합니다.

익명 식별은 인증되지 않은 엔터티를 식별해야 하는 경우와 권한 부여가 필요한 경우에 사용됩니다. 자세한 내용은 anonymousIdentification 요소(ASP.NET 설정 스키마)를 참조하세요.

적용 대상

추가 정보