FormsAuthenticationTicket 클래스

정의

사용자 식별을 위해 폼 인증에서 사용되는 티켓의 속성 및 값에 액세스할 수 있도록 합니다. 이 클래스는 상속될 수 없습니다.

public ref class FormsAuthenticationTicket sealed
[System.Serializable]
public sealed class FormsAuthenticationTicket
[<System.Serializable>]
type FormsAuthenticationTicket = class
Public NotInheritable Class FormsAuthenticationTicket
상속
FormsAuthenticationTicket
특성

예제

결과 저장 하는 다음 코드 예제는 Encrypt 메서드를 사용 하 여 쿠키를 FormsCookieName 에서 반환 된 URL로 사용자를 리디렉션합니다는 GetRedirectUrl 메서드.

중요

이 예제에서는 잠재적 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 포함 되어 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  private void Login_Click(Object sender, EventArgs e)
  {
    // Create a custom FormsAuthenticationTicket containing
    // application specific data for the user.

    string username     = UserNameTextBox.Text;
    string password     = UserPassTextBox.Text;
    bool   isPersistent = false;

    if (Membership.ValidateUser(username, password))
    {
      string userData = "ApplicationSpecific data for this user.";

      FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
        username,
        DateTime.Now,
        DateTime.Now.AddMinutes(30),
        isPersistent,
        userData,
        FormsAuthentication.FormsCookiePath);

      // Encrypt the ticket.
      string encTicket = FormsAuthentication.Encrypt(ticket);

      // Create the cookie.
      Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

      // Redirect back to original URL.
      Response.Redirect(FormsAuthentication.GetRedirectUrl(username, isPersistent));
    }
    else
    {
      Msg.Text = "Login failed. Please check your user name and password and try again.";
    }
  }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Forms Authentication Login</title>
</head>
<body>
    <form id="form1" runat="server">
        <span style="BACKGROUND: #80ff80; font-weight:bold"> 
            Login Page
        </span> 
        <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />
        <table border="0">
            <tbody>
                <tr>
                    <td>Username:</td>
                    <td><asp:TextBox id="UserNameTextBox" runat="server" /></td>
                    <td>
                      <asp:RequiredFieldValidator id="RequiredFieldValidator1" 
                                                  runat="server" ErrorMessage="*" 
                                                  Display="Static" 
                                                  ControlToValidate="UserNameTextBox" />
                    </td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><asp:TextBox id="UserPassTextBox" TextMode="Password" runat="server" /></td>
                    <td>
                      <asp:RequiredFieldValidator id="RequiredFieldValidator2" 
                                                  runat="server" ErrorMessage="*" 
                                                  Display="Static" 
                                                  ControlToValidate="UserPassTextBox" />
                    </td>
                </tr>
            </tbody>
        </table>
        <input type="submit" value="Login" runat="server" onserverclick="Login_Click" />
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Private Sub Login_Click(sender As Object, e As EventArgs)
  
    ' Create a custom FormsAuthenticationTicket containing
    ' application specific data for the user.

        Dim username As String = UserNameTextBox.Text
        Dim password As String = UserPassTextBox.Text
        Dim isPersistent As Boolean = False

    If Membership.ValidateUser(username, password) Then
    
      Dim userData As String = "ApplicationSpecific data for this user."

      Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, _
        username, _
        DateTime.Now, _
        DateTime.Now.AddMinutes(30), _
        isPersistent, _
        userData, _
        FormsAuthentication.FormsCookiePath)

      ' Encrypt the ticket.
      Dim encTicket As String = FormsAuthentication.Encrypt(ticket)

      ' Create the cookie.
      Response.Cookies.Add(New HttpCookie(FormsAuthentication.FormsCookieName, encTicket))

      ' Redirect back to original URL.
      Response.Redirect(FormsAuthentication.GetRedirectUrl(username, isPersistent))
    Else    
      Msg.Text = "Login failed. Please check your user name and password and try again."
    End If
  End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Forms Authentication Login</title>
</head>
<body>
    <form id="form1" runat="server">
        <span style="BACKGROUND:#80ff80; font-weight:bold"> 
          Login Page
        </span> 
        <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />
        <table border="0">
            <tbody>
                <tr>
                    <td>Username:</td>
                    <td><asp:TextBox id="UserNameTextBox" runat="server" /></td>
                    <td>
                      <asp:RequiredFieldValidator id="RequiredFieldValidator1" 
                                                  runat="server" ErrorMessage="*" 
                                                  Display="Static" 
                                                  ControlToValidate="UserNameTextBox" />
                    </td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><asp:TextBox id="UserPassTextBox" TextMode="Password" runat="server" /></td>
                    <td>
                      <asp:RequiredFieldValidator id="RequiredFieldValidator2" 
                                                  runat="server" ErrorMessage="*" 
                                                  Display="Static" 
                                                  ControlToValidate="UserPassTextBox" />
                    </td>
                </tr>
            </tbody>
        </table>
        <input type="submit" value="Login" runat="server" onserverclick="Login_Click" />
    </form>
</body>
</html>

설명

FormsAuthenticationTicket 클래스 폼 인증에서 인증된 된 사용자를 식별 하는 데 사용 되는 인증 티켓을 나타내는 개체를 만드는 데 사용 됩니다. 속성 및 폼 인증 티켓의 값을 URL 또는 쿠키에 저장 된 암호화 된 문자열에서 변환 됩니다.

FormsAuthentication 클래스를 제공는 Encrypt URL 또는 쿠키에 저장할 수 있는 문자열 값을 만드는 메서드를 FormsAuthenticationTicket입니다. FormsAuthentication 클래스도 제공을 Decrypt 메서드를를 FormsAuthenticationTicket 폼 인증 쿠키 또는 URL에서 암호화 된 인증 티켓에서 개체 검색 합니다.

FormsAuthenticationTicket 를 사용 하 여 액세스할 수 있는 현재 인증 된 사용자 수에 대 한는 Ticket 의 속성을 FormsIdentity 클래스입니다. 현재 액세스할 수 있습니다 FormsIdentity 캐스팅 하 여 개체를 Identity 속성이 현재 User 형식으로 FormsIdentity입니다.

생성자

FormsAuthenticationTicket(Int32, String, DateTime, DateTime, Boolean, String)

쿠키 이름, 버전, 만료일, 발행일, 지속성 및 사용자별 데이터를 사용하여 FormsAuthenticationTicket 클래스의 새 인스턴스를 초기화합니다. 쿠키 경로는 애플리케이션 구성 파일에 설정된 기본값으로 설정됩니다.

FormsAuthenticationTicket(Int32, String, DateTime, DateTime, Boolean, String, String)

FormsAuthenticationTicket 클래스의 새 인스턴스와 쿠키 이름, 버전, 디렉터리 경로, 발행일, 만료일, 지속성 및 사용자 정의 데이터를 초기화합니다.

FormsAuthenticationTicket(String, Boolean, Int32)

쿠키 이름과 만료 정보를 사용하여 FormsAuthenticationTicket 클래스의 새 인스턴스를 초기화합니다.

속성

CookiePath

폼 인증 티켓에 대한 쿠키 경로를 가져옵니다.

Expiration

폼 인증 티켓이 만료되는 현지 날짜와 시간을 가져옵니다.

Expired

폼 인증 티켓이 만료되었는지 여부를 나타내는 값을 가져옵니다.

IsPersistent

폼 인증 티켓 정보가 들어 있는 쿠키가 영구 쿠키인지 여부를 나타내는 값을 가져옵니다.

IssueDate

폼 인증 티켓이 처음 발행된 현지 날짜와 시간을 가져옵니다.

Name

폼 인증 티켓과 관련된 사용자 이름을 가져옵니다.

UserData

티켓과 함께 저장되는 사용자별 문자열을 가져옵니다.

Version

티켓의 버전 번호를 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보