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

注解

当 为 时CacheRolesInCookietrueToEncryptedTicket方法返回的值存储在角色 Cookie 中。

适用于

另请参阅