RolePrincipal.Identity 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得目前 HTTP 要求的安全性識別。
public:
property System::Security::Principal::IIdentity ^ Identity { System::Security::Principal::IIdentity ^ get(); };
public:
virtual property System::Security::Principal::IIdentity ^ Identity { System::Security::Principal::IIdentity ^ get(); };
public System.Security.Principal.IIdentity Identity { get; }
public override System.Security.Principal.IIdentity Identity { get; }
member this.Identity : System.Security.Principal.IIdentity
Public ReadOnly Property Identity As IIdentity
Public Overrides ReadOnly Property Identity As IIdentity
屬性值
目前 HTTP 要求的安全性識別。
實作
範例
如果啟用角色管理,下列範例會顯示目前使用者的角色快取資訊。 如需啟用角色管理的詳細資訊,請參閱 Roles 類別。
<%@ 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">
public void Page_Load()
{
try
{
RolePrincipal r = (RolePrincipal)User;
IsCachedLabel.Text = r.IsRoleListCached.ToString();
CacheChangedLabel.Text = r.CachedListChanged.ToString();
ExpiredLabel.Text = r.Expired.ToString();
VersionLabel.Text = r.Version.ToString();
IssueDateLabel.Text = r.IssueDate.ToString();
ExpireDateLabel.Text = r.ExpireDate.ToString();
CookiePathLabel.Text = r.CookiePath;
Msg.Text = "";
}
catch (InvalidCastException)
{
Msg.Text = "User is not of type RolePrincipal. Are roles enabled?";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Role Information</title>
</head>
<body>
<form id="form1" runat="server">
Role Information for <b><%=User.Identity.Name%></b>.<br />
<asp:Label id="Msg" runat="Server" ForeColor="maroon" /><br />
<table border="1" cellpadding="4" cellspacing="4">
<tr>
<td>IsRoleListCached</td>
<td><asp:Label id="IsCachedLabel" runat="Server" /></td>
</tr>
<tr>
<td>CachedListChanged</td>
<td><asp:Label id="CacheChangedLabel" runat="Server" /></td>
</tr>
<tr>
<td>Expired</td>
<td><asp:Label id="ExpiredLabel" runat="Server" /></td>
</tr>
<tr>
<td>Version</td>
<td><asp:Label id="VersionLabel" runat="Server" /></td>
</tr>
<tr>
<td>IssueDate</td>
<td><asp:Label id="IssueDateLabel" runat="Server" /></td>
</tr>
<tr>
<td>ExpireDate</td>
<td><asp:Label id="ExpireDateLabel" runat="Server" /></td>
</tr>
<tr>
<td>CookiePath</td>
<td><asp:Label id="CookiePathLabel" runat="Server" /></td>
</tr>
</table>
</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">
Public Sub Page_Load()
Try
Dim r As RolePrincipal = CType(User, RolePrincipal)
IsCachedLabel.Text = r.IsRoleListCached.ToString()
CacheChangedLabel.Text = r.CachedListChanged.ToString()
ExpiredLabel.Text = r.Expired.ToString()
VersionLabel.Text = r.Version.ToString()
IssueDateLabel.Text = r.IssueDate.ToString()
ExpireDateLabel.Text = r.ExpireDate.ToString()
CookiePathLabel.Text = r.CookiePath
Msg.Text = ""
Catch e As InvalidCastException
Msg.Text = "User is not of type RolePrincipal. Are roles enabled?"
End Try
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Role Information</title>
</head>
<body>
<form id="form1" runat="server">
Role Information for <b><%=User.Identity.Name%></b>.<br />
<asp:Label id="Msg" runat="Server" ForeColor="maroon" /><br />
<table border="1" cellpadding="4" cellspacing="4">
<tr>
<td>IsRoleListCached</td>
<td><asp:Label id="IsCachedLabel" runat="Server" /></td>
</tr>
<tr>
<td>CachedListChanged</td>
<td><asp:Label id="CacheChangedLabel" runat="Server" /></td>
</tr>
<tr>
<td>Expired</td>
<td><asp:Label id="ExpiredLabel" runat="Server" /></td>
</tr>
<tr>
<td>Version</td>
<td><asp:Label id="VersionLabel" runat="Server" /></td>
</tr>
<tr>
<td>IssueDate</td>
<td><asp:Label id="IssueDateLabel" runat="Server" /></td>
</tr>
<tr>
<td>ExpireDate</td>
<td><asp:Label id="ExpireDateLabel" runat="Server" /></td>
</tr>
<tr>
<td>CookiePath</td>
<td><asp:Label id="CookiePathLabel" runat="Server" /></td>
</tr>
</table>
</form>
</body>
</html>
備註
Identity RolePrincipal呼叫建構函式時RolePrincipal,會設定 物件的 。