本文整理汇总了C#中System.Web.Security.FormsAuthenticationTicket.IsNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# FormsAuthenticationTicket.IsNotNull方法的具体用法?C# FormsAuthenticationTicket.IsNotNull怎么用?C# FormsAuthenticationTicket.IsNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Security.FormsAuthenticationTicket
的用法示例。
在下文中一共展示了FormsAuthenticationTicket.IsNotNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUpdatedPrincipalFor
public IPrincipal GetUpdatedPrincipalFor(IUser user, bool stayLoggedIn = false, FormsAuthenticationTicket currentTicket = null)
{
Verify.NotNull(user, "user");
Verify.False(user.IsNew, "user.IsNew"); // User must be saved to the DB first.
var issueDate = DateTime.Now;
if (currentTicket.IsNotNull())
{
issueDate = currentTicket.IssueDate;
stayLoggedIn = currentTicket.IsPersistent;
}
var userData = SerializeUser(user);
var newTicket = NewTicketFrom(user.UserName, issueDate, ExpirationTime, stayLoggedIn, userData);
// Because of this, this method must be called after successful authentication
RenewCookieWith(newTicket);
IIdentity identity = new FormsIdentity(newTicket);
var roleNames = user.Roles.Select(r => r.Name).ToArray();
// TODO: HAS 03/03/2013 Create a custom Principal type to hold custom data
return new GenericPrincipal(identity, roleNames);
}