共用方式為


RolePrincipal.ToEncryptedTicket 方法

定義

傳回使用 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

備註

當 為 trueCacheRolesInCookie,方法傳ToEncryptedTicket回的值會儲存在角色 Cookie 中。

適用於

另請參閱