FormsIdentity 클래스

정의

폼 인증 중에 인증된 사용자 ID를 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class FormsIdentity sealed : System::Security::Principal::IIdentity
public ref class FormsIdentity : System::Security::Principal::IIdentity
public ref class FormsIdentity : System::Security::Claims::ClaimsIdentity
[System.Serializable]
public sealed class FormsIdentity : System.Security.Principal.IIdentity
[System.Serializable]
public class FormsIdentity : System.Security.Principal.IIdentity
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(false)]
public class FormsIdentity : System.Security.Claims.ClaimsIdentity
[<System.Serializable>]
type FormsIdentity = class
    interface IIdentity
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type FormsIdentity = class
    inherit ClaimsIdentity
Public NotInheritable Class FormsIdentity
Implements IIdentity
Public Class FormsIdentity
Implements IIdentity
Public Class FormsIdentity
Inherits ClaimsIdentity
상속
FormsIdentity
상속
FormsIdentity
특성
구현

예제

다음 코드 예제에서는 를 생성 FormsAuthenticationTicket 한 다음, 이를 사용하여 사용자가 양식에 올바른 사용자 이름과 암호를 제공하는지 여부에 따라 클래스의 FormsIdentity instance 만듭니다.

<%@ Page Language="C#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="System.Web.Security" %>
<script runat="server">
    protected void Login_Click(object sender, EventArgs e)
    {
        bool isAuthenticated = false;
        if (string.Compare(UserNameTextBox.Text, "UserName", true,
        CultureInfo.InvariantCulture) == 0)
        {
            if (string.Compare(PasswordTextBox.Text, "Password", true,
            CultureInfo.InvariantCulture) == 0)
            {
                isAuthenticated = true;
            }
        }
        else isAuthenticated = false;
        
        // Create the formsIdentity for the user.
        CreateformsIdentity(UserNameTextBox.Text, isAuthenticated);
    }
    private void CreateformsIdentity(string userName, bool isAuthenticated)
    {
        FormsIdentity formsID;
        FormsAuthenticationTicket authenticationTicket;
        
        if (isAuthenticated)
        {
            // If authentication passed, create a ticket 
            // as a Manager that expires in 15 minutes.
            authenticationTicket = new FormsAuthenticationTicket(1, userName,
                DateTime.Now, DateTime.Now.AddMinutes(15), false, "Manager");
        }
        else
        {
            // If authentication failed, create a ticket 
            // as a guest that expired 5 minutes ago.
            authenticationTicket = new FormsAuthenticationTicket(1, userName,
                DateTime.Now, DateTime.Now.Subtract(new TimeSpan(0, 5, 0)),
                false, "Guest");
        }

        // Create form identity from FormsAuthenticationTicket.
        formsID = new FormsIdentity(authenticationTicket);
        Response.Clear();
        Response.Write("Authentication Type: " + formsID.AuthenticationType +
            "<BR>");

        // Get FormsAuthenticationTicket from the FormIdentity
        FormsAuthenticationTicket ticket = formsID.Ticket;
        if (ticket.Expired)
        {
            Response.Write("Authentication failed, so the role is set to " +
                ticket.UserData);
        }
        else
        {
            Response.Write("Authentication succeeded, so the role is set to " +
                ticket.UserData);
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>WebForm1</title>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <asp:Label id="UserIdLabel" runat="server"
                style="left: 144px; position: absolute; top: 160px">
                User-ID:</asp:Label>
            <asp:Label id="PasswordLabel" runat="server"
                style="left: 144px; position: absolute; top: 200px">
                Password:</asp:Label>
            <asp:TextBox id="UserNameTextBox" runat="server"
                style="left: 232px; position: absolute; top: 160px;
                width:182px; height:22px"></asp:TextBox>
            <asp:TextBox id="PasswordTextBox" runat="server"
                style="left: 232px; position: absolute; top: 200px;
                width:181px; height:22px" TextMode="Password">
                </asp:TextBox>
            <asp:Button id="Login" runat="server" Text="Login"
                style="left: 232px; position: absolute; top: 232px; 
                width:100px" OnClick="Login_Click"></asp:Button>
        </form>
    </body>
</html>
<%@ Page Language="vb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ Import Namespace="System.Globalization" %>
<script runat="server">
    Private Sub Login_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Login.Click

        ' For the example, the user name must be "UserName" and the password
        ' must be "Password" for authentication to succeed.
        Dim isAuthenticated As Boolean
        If String.Compare(UserNameTextBox.Text, "UserName", True, _
            CultureInfo.InvariantCulture) = 0 Then
            If String.Compare(PasswordTextBox.Text, "Password", True, _
                CultureInfo.InvariantCulture) = 0 Then
                isAuthenticated = True
            End If
        Else
            isAuthenticated = False
        End If

        ' Create the FormsIdentity for the user.
        CreateFormsIdentity(UserNameTextBox.Text, isAuthenticated)

    End Sub

    Private Sub CreateFormsIdentity(ByVal userName As String, _
        ByVal isAuthenticated As Boolean)

        Dim formsId As System.Web.Security.FormsIdentity
        Dim authenticationTicket As _
            System.Web.Security.FormsAuthenticationTicket

        If isAuthenticated Then
            ' If authentication passed, create a ticket 
            ' as a Manager that expires in 15 minutes.
            authenticationTicket = _
                New FormsAuthenticationTicket(1, userName, DateTime.Now, _
                DateTime.Now.AddMinutes(15), False, "Manager")
        Else
            ' If authentication failed, create a ticket 
            ' as a guest that expired 5 minutes ago.
            authenticationTicket = _
                New FormsAuthenticationTicket(1, userName, DateTime.Now, _
                DateTime.Now.Subtract(New TimeSpan(0, 5, 0)), False, "Guest")
        End If

        ' Create form identity from FormsAuthenticationTicket.
        formsId = New FormsIdentity(authenticationTicket)

        Response.Clear()
        Response.Write("Authenticate Type: " & _
            formsId.AuthenticationType & "<BR>")

        ' Get FormsAuthenticationTicket from the FormIdentity
        Dim ticket As FormsAuthenticationTicket = formsId.Ticket()
        If ticket.Expired Then
            Response.Write("Authentication failed, so the role is set to " & _
                ticket.UserData)
        Else
            Response.Write("Authentication succeeded, so the role is set to " & _
                ticket.UserData)
        End If
    End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>WebForm1</title>
    </head>
    <body>
        <form id="Form1" method="post" runat="server">
            <asp:Label id="UserIdLabel" runat="server"
                style="left: 144px; position: absolute; top: 160px">
                User-ID:</asp:Label>
            <asp:Label id="PasswordLabel" runat="server"
                style="left: 144px; position: absolute; top: 200px">
                Password:</asp:Label>
            <asp:TextBox id="UserNameTextBox" runat="server"
                style="left: 232px; position: absolute; top: 160px;
                width:182px; height:22px"></asp:TextBox>
            <asp:TextBox id="PasswordTextBox" runat="server"
                style="left: 232px; position: absolute; top: 200px;
                width:181px; height:22px" TextMode="Password">
                </asp:TextBox>
            <asp:Button id="Login" runat="server" Text="Login"
                style="left: 232px; position: absolute; top: 232px; 
                width:100px"></asp:Button>
        </form>
    </body>
</html>

설명

FormsIdentity 클래스는 사용자가 양식 인증으로 인증될 때 에서 사용됩니다FormsAuthenticationModule. 클래스의 FormsIdentity instance 폼 인증 쿠키 또는 URL에서 암호 해독 되는 를 사용 하 여 FormsAuthenticationTicket 만들어집니다. 클래스의 FormsIdentity 새 instance 현재 HttpContext의 속성 값 User 으로 설정된 새 GenericPrincipal 개체를 생성하는 데 사용됩니다.

생성자

FormsIdentity(FormsAuthenticationTicket)

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

FormsIdentity(FormsIdentity)

지정된 ID를 FormsIdentity 클래스의 새 인스턴스를 초기화합니다.

필드

DefaultIssuer

기본 발급자인 "로컬 인증 기관"입니다.

(다음에서 상속됨 ClaimsIdentity)
DefaultNameClaimType

기본 이름 클레임 형식은 Name입니다.

(다음에서 상속됨 ClaimsIdentity)
DefaultRoleClaimType

기본 역할 클레임 형식은 Role입니다.

(다음에서 상속됨 ClaimsIdentity)

속성

Actor

위임 권한이 부여된 발신자의 ID를 가져오거나 설정합니다.

(다음에서 상속됨 ClaimsIdentity)
AuthenticationType

인증된 ID의 형식을 가져옵니다.

BootstrapContext

이 클레임 ID를 만드는 데 사용된 토큰을 가져오거나 설정합니다.

(다음에서 상속됨 ClaimsIdentity)
Claims

이 ID와 연결된 클레임의 컬렉션을 가져옵니다.

CustomSerializationData

파생된 형식에서 제공하는 추가 데이터를 포함합니다. 일반적으로 WriteTo(BinaryWriter, Byte[])를 호출할 때 설정합니다.

(다음에서 상속됨 ClaimsIdentity)
IsAuthenticated

인증되었는지 여부를 나타내는 값을 가져옵니다.

Label

이 클레임 ID에 대한 레이블을 가져오거나 설정합니다.

(다음에서 상속됨 ClaimsIdentity)
Name

폼 ID의 사용자 이름을 가져옵니다.

NameClaimType

이 클레임 ID의 Name 속성 값을 제공하는 클레임을 확인하는 데 사용되는 클레임 형식을 가져옵니다.

(다음에서 상속됨 ClaimsIdentity)
RoleClaimType

이 클레임 ID의 클레임 중에서 .NET 역할로 해석될 클레임 형식을 가져옵니다.

(다음에서 상속됨 ClaimsIdentity)
Ticket

폼 인증 사용자 ID의 FormsAuthenticationTicket을 가져옵니다.

메서드

AddClaim(Claim)

이 클레임 ID에 단일 클레임을 추가합니다.

(다음에서 상속됨 ClaimsIdentity)
AddClaims(IEnumerable<Claim>)

이 클레임 ID에 클레임 목록을 추가합니다.

(다음에서 상속됨 ClaimsIdentity)
Clone()

현재 FormsIdentity 인스턴스의 복사본을 가져옵니다.

CreateClaim(BinaryReader)

사용자 지정 Claim을 만들 파생된 형식에 대한 확장성 지점을 제공합니다.

(다음에서 상속됨 ClaimsIdentity)
Equals(Object)

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

(다음에서 상속됨 Object)
FindAll(Predicate<Claim>)

지정된 조건자와 일치하는 클레임을 모두 검색합니다.

(다음에서 상속됨 ClaimsIdentity)
FindAll(String)

지정된 클레임 형식이 있는 클레임을 모두 검색합니다.

(다음에서 상속됨 ClaimsIdentity)
FindFirst(Predicate<Claim>)

지정된 조건자와 일치하는 첫 번째 클레임을 검색합니다.

(다음에서 상속됨 ClaimsIdentity)
FindFirst(String)

지정된 클레임 형식으로 첫 번째 클레임을 검색합니다.

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

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

(다음에서 상속됨 Object)
GetObjectData(SerializationInfo, StreamingContext)

현재 SerializationInfo 개체를 serialize하는 데 필요한 데이터로 ClaimsIdentity를 채웁니다.

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

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

(다음에서 상속됨 Object)
HasClaim(Predicate<Claim>)

이 클레임에 지정된 조건자와 일치하는 클레임이 있는지 여부를 확인합니다.

(다음에서 상속됨 ClaimsIdentity)
HasClaim(String, String)

이 클레임 ID에 지정된 클레임 형식 및 값을 가진 클레임이 있는지 여부를 확인합니다.

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

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

(다음에서 상속됨 Object)
RemoveClaim(Claim)

클레임 ID에서 클레임을 제거하려고 시도합니다.

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

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

(다음에서 상속됨 Object)
TryRemoveClaim(Claim)

클레임 ID에서 클레임을 제거하려고 시도합니다.

(다음에서 상속됨 ClaimsIdentity)
WriteTo(BinaryWriter)

BinaryWriter를 사용하여 직렬화합니다.

(다음에서 상속됨 ClaimsIdentity)
WriteTo(BinaryWriter, Byte[])

BinaryWriter를 사용하여 직렬화합니다.

(다음에서 상속됨 ClaimsIdentity)

적용 대상

추가 정보