FormsAuthenticationTicket.Name 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
폼 인증 티켓과 관련된 사용자 이름을 가져옵니다.
public:
property System::String ^ Name { System::String ^ get(); };
public string Name { get; }
member this.Name : string
Public ReadOnly Property Name As String
속성 값
폼 인증 티켓과 관련된 사용자 이름입니다.
예제
다음 코드 예제에서는 속성 값이 표시 됩니다는 FormsAuthenticationTicket 현재 로그온 한 사용자에 대 한 합니다.
참고
로그온 한 사용자가 없는, 하는 경우는 Identity 속성이 null
캐스팅 하려고 하면 컴파일러 예외를 받지 않게 됩니다는 Identity 속성을 FormsIdentity 개체입니다.
<%@ Page Language="C#" AutoEventWireup="true"%>
<!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 Page_Load(Object Src, EventArgs e)
{
Welcome.InnerHtml = "Hello, " +
Server.HtmlEncode(User.Identity.Name);
FormsIdentity id = (FormsIdentity)User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
cookiePath.Text = ticket.CookiePath;
expireDate.Text = ticket.Expiration.ToString();
expired.Text = ticket.Expired.ToString();
isPersistent.Text = ticket.IsPersistent.ToString();
issueDate.Text = ticket.IssueDate.ToString();
name.Text = ticket.Name;
userData.Text = ticket.UserData;
version.Text = ticket.Version.ToString();
}
private void Signout_Click(Object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Write("Logged out - cookie deleted.");
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Forms Authentication</title>
</head>
<body>
<h3>Forms Authentication Example</h3>
<span id="Welcome" runat="server"> </span>
<form id="form1" runat="server">
<input type="submit" value="Signout" runat="server" onserverclick="Signout_Click" />
<h3>Forms Authentication Ticket Properties</h3>
<table>
<tbody>
<tr>
<td>
CookiePath:
</td>
<td><asp:Label id="cookiePath" runat="server" />
</td>
</tr>
<tr>
<td>
Expiration:
</td>
<td><asp:Label id="expireDate" runat="server" />
</td>
</tr>
<tr>
<td>
Expired:
</td>
<td><asp:Label id="expired" runat="server" />
</td>
</tr>
<tr>
<td>
IsPersistent:
</td>
<td><asp:Label id="isPersistent" runat="server" />
</td>
</tr>
<tr>
<td>
IssueDate:
</td>
<td><asp:Label id="issueDate" runat="server" />
</td>
</tr>
<tr>
<td>
Name:
</td>
<td><asp:Label id="name" runat="server" />
</td>
</tr>
<tr>
<td>
UserData:
</td>
<td><asp:Label id="userData" runat="server" />
</td>
</tr>
<tr>
<td>
Version:
</td>
<td><asp:Label id="version" runat="server" />
</td>
</tr>
</tbody>
</table>
<p>
</p>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="true"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Welcome.InnerHtml = "Hello, " + _
Server.HtmlEncode(User.Identity.Name)
Dim id As FormsIdentity = CType(User.Identity, FormsIdentity)
Dim ticket As FormsAuthenticationTicket = id.Ticket
cookiePath.Text = ticket.CookiePath
expireDate.Text = ticket.Expiration.ToString()
expired.Text = ticket.Expired.ToString()
isPersistent.Text = ticket.IsPersistent.ToString()
issueDate.Text = ticket.IssueDate.ToString()
name.Text = ticket.Name
userData.Text = ticket.UserData
version.Text = ticket.Version.ToString()
End Sub
Sub Signout_Click(sender As Object, e As EventArgs)
FormsAuthentication.SignOut()
Response.Write("Logged out - cookie deleted.")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Forms Authentication</title>
</head>
<body>
<h3>Forms Authentication Example</h3>
<span id="Welcome" runat="server"> </span>
<form id="form1" runat="server">
<input type="submit" value="Signout" runat="server" onserverclick="Signout_Click" />
<h3>Forms Authentication Ticket Properties</h3>
<table>
<tbody>
<tr>
<td>
CookiePath:
</td>
<td><asp:Label id="cookiePath" runat="server" />
</td>
</tr>
<tr>
<td>
Expiration:
</td>
<td><asp:Label id="expireDate" runat="server" />
</td>
</tr>
<tr>
<td>
Expired:
</td>
<td><asp:Label id="expired" runat="server" />
</td>
</tr>
<tr>
<td>
IsPersistent:
</td>
<td><asp:Label id="isPersistent" runat="server" />
</td>
</tr>
<tr>
<td>
IssueDate:
</td>
<td><asp:Label id="issueDate" runat="server" />
</td>
</tr>
<tr>
<td>
Name:
</td>
<td><asp:Label id="name" runat="server" />
</td>
</tr>
<tr>
<td>
UserData:
</td>
<td><asp:Label id="userData" runat="server" />
</td>
</tr>
<tr>
<td>
Version:
</td>
<td><asp:Label id="version" runat="server" />
</td>
</tr>
</tbody>
</table>
<p>
</p>
</form>
</body>
</html>
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET