다음을 통해 공유


FormsAuthenticationTicket 생성자

정의

FormsAuthenticationTicket 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
FormsAuthenticationTicket(String, Boolean, Int32)

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

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

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

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

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

FormsAuthenticationTicket(String, Boolean, Int32)

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

public:
 FormsAuthenticationTicket(System::String ^ name, bool isPersistent, int timeout);
public FormsAuthenticationTicket(string name, bool isPersistent, int timeout);
new System.Web.Security.FormsAuthenticationTicket : string * bool * int -> System.Web.Security.FormsAuthenticationTicket
Public Sub New (name As String, isPersistent As Boolean, timeout As Integer)

매개 변수

name
String

티켓과 연결된 사용자 이름입니다.

isPersistent
Boolean

true티켓이 영구 쿠키에 저장되면(브라우저 세션 간에 저장됨) 그렇지 않으면 . false 티켓이 URL에 저장되면 이 값은 무시됩니다.

timeout
Int32

인증 티켓이 유효한 시간(분)입니다.

설명

이 생성자가 만든 개체는 FormsAuthenticationTicket 속성 값FormsCookiePath, 값 2, Version 현재 로컬 날짜 및 시간 값, UserDataIssueDate 빈 문자열 값("") 및 현재 로컬 날짜 및 Expiration 시간으로 설정된 값과 매개 변수 값 timeout 으로 설정된 값을 갖 CookiePath 습니다.

추가 정보

적용 대상

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

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

public:
 FormsAuthenticationTicket(int version, System::String ^ name, DateTime issueDate, DateTime expiration, bool isPersistent, System::String ^ userData);
public FormsAuthenticationTicket(int version, string name, DateTime issueDate, DateTime expiration, bool isPersistent, string userData);
new System.Web.Security.FormsAuthenticationTicket : int * string * DateTime * DateTime * bool * string -> System.Web.Security.FormsAuthenticationTicket
Public Sub New (version As Integer, name As String, issueDate As DateTime, expiration As DateTime, isPersistent As Boolean, userData As String)

매개 변수

version
Int32

티켓의 버전 번호입니다.

name
String

티켓과 연결된 사용자 이름입니다.

issueDate
DateTime

티켓이 발행된 현지 날짜 및 시간입니다.

expiration
DateTime

티켓이 만료되는 현지 날짜 및 시간입니다.

isPersistent
Boolean

true티켓이 영구 쿠키에 저장되면(브라우저 세션 간에 저장됨) 그렇지 않으면 . false 티켓이 URL에 저장되면 이 값은 무시됩니다.

userData
String

티켓과 함께 저장할 사용자별 데이터입니다.

설명

FormsAuthenticationTicket 이 생성자가 만든 개체의 값은 CookiePath 값으로 FormsCookiePath설정됩니다.

메모

매개 변수는 . userData 일 수 없습니다 null.

추가 정보

적용 대상

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

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

public:
 FormsAuthenticationTicket(int version, System::String ^ name, DateTime issueDate, DateTime expiration, bool isPersistent, System::String ^ userData, System::String ^ cookiePath);
public FormsAuthenticationTicket(int version, string name, DateTime issueDate, DateTime expiration, bool isPersistent, string userData, string cookiePath);
new System.Web.Security.FormsAuthenticationTicket : int * string * DateTime * DateTime * bool * string * string -> System.Web.Security.FormsAuthenticationTicket
Public Sub New (version As Integer, name As String, issueDate As DateTime, expiration As DateTime, isPersistent As Boolean, userData As String, cookiePath As String)

매개 변수

version
Int32

티켓의 버전 번호입니다.

name
String

티켓과 연결된 사용자 이름입니다.

issueDate
DateTime

티켓이 발행된 현지 날짜 및 시간입니다.

expiration
DateTime

티켓이 만료되는 현지 날짜 및 시간입니다.

isPersistent
Boolean

true티켓이 영구 쿠키에 저장되면(브라우저 세션 간에 저장됨) 그렇지 않으면 . false 티켓이 URL에 저장되면 이 값은 무시됩니다.

userData
String

티켓과 함께 저장할 사용자별 데이터입니다.

cookiePath
String

쿠키에 저장될 때의 티켓 경로입니다.

예제

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

중요합니다

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

<%@ 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>

설명

메모

매개 변수는 . userData 일 수 없습니다 null.

추가 정보

적용 대상