RolePrincipal.ToEncryptedTicket 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回使用 RolePrincipal 物件快取的角色資訊,該資訊根據 CookieProtectionValue 進行加密。
public:
System::String ^ ToEncryptedTicket();
public string ToEncryptedTicket ();
member this.ToEncryptedTicket : unit -> string
Public Function ToEncryptedTicket () As String
傳回
使用 RolePrincipal 物件快取的角色資訊,該資訊根據 CookieProtectionValue 進行加密。
範例
下列程式代碼範例會將 方法的結果 ToEncryptedTicket 寫入角色Cookie。
try
{
RolePrincipal r = (RolePrincipal)User;
string eTicket = r.ToEncryptedTicket();
HttpCookie cookie = new HttpCookie(Roles.CookieName, eTicket);
cookie.Path = Roles.CookiePath;
cookie.Expires = r.ExpireDate;
Response.Cookies.Add(cookie);
}
catch (InvalidCastException)
{
Response.Write("User is not of type RolePrincipal. Are roles enabled?");
}
Try
Dim r As RolePrincipal = CType(User, RolePrincipal)
Dim eTicket As String = r.ToEncryptedTicket()
Dim cookie As HttpCookie = New HttpCookie(Roles.CookieName, eTicket)
cookie.Path = Roles.CookiePath
cookie.Expires = r.ExpireDate
Response.Cookies.Add(cookie)
Catch e As InvalidCastException
Response.Write("User is not of type RolePrincipal. Are roles enabled?")
End Try
備註
當 為 true
時CacheRolesInCookie,方法傳ToEncryptedTicket回的值會儲存在角色 Cookie 中。