RolePrincipal.ToEncryptedTicket 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回利用 RolePrincipal 对象缓存并根据 CookieProtectionValue 加密的角色信息。
public:
 System::String ^ ToEncryptedTicket();public string ToEncryptedTicket();member this.ToEncryptedTicket : unit -> stringPublic 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
注解
当 为 时CacheRolesInCookietrue,ToEncryptedTicket方法返回的值存储在角色 Cookie 中。