本文整理汇总了C#中System.Web.HttpContextWrapper.SetAuthenticationTicket方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextWrapper.SetAuthenticationTicket方法的具体用法?C# HttpContextWrapper.SetAuthenticationTicket怎么用?C# HttpContextWrapper.SetAuthenticationTicket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpContextWrapper
的用法示例。
在下文中一共展示了HttpContextWrapper.SetAuthenticationTicket方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AuthenticateHostAdmin
/// <summary>
/// Authenticates the host admin.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
/// <param name="persist">if set to <c>true</c> [persist].</param>
/// <returns></returns>
public static bool AuthenticateHostAdmin(this HostInfo host, string username, string password, bool persist)
{
if (!host.ValidateHostAdminPassword(username, password))
{
return false;
}
if (Log.IsDebugEnabled)
{
Log.Debug("SetAuthenticationTicket-HostAdmins for " + username);
}
HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);
httpContext.SetAuthenticationTicket(null, username, persist, true, "HostAdmins");
return true;
}
示例2: Authenticate
/// <summary>
/// Check to see if the supplied OpenID claim is valid for the current blog. If so,
/// Set the user's FormsAuthentication Ticket This method will handle passwords for
/// both hashed and non-hashed configurations
/// We're comparing URI objects rather than using simple string compare because
/// functionally equivalent URI's may not pass string comparaisons, e.g.
/// such as http://example.myopenid.com/ and http://example.myopenid.com (trailing /)
/// </summary>
public static bool Authenticate(string claimedIdentifier, bool persist)
{
Blog currentBlog = Config.CurrentBlog;
if (currentBlog == null)
{
return false;
}
//If the current blog doesn't have a valid OpenID URI, must fail
if (!Uri.IsWellFormedUriString(currentBlog.OpenIdUrl, UriKind.Absolute))
{
return false;
}
//If the cliamed identifier isn't a valid OpenID URI, must fail
if (!Uri.IsWellFormedUriString(claimedIdentifier, UriKind.Absolute))
{
return false;
}
var currentBlogClaimUri = new Uri(currentBlog.OpenIdUrl);
var claimedUri = new Uri(claimedIdentifier);
if (claimedUri.Host != currentBlogClaimUri.Host ||
claimedUri.AbsolutePath != currentBlogClaimUri.AbsolutePath ||
claimedUri.Query != currentBlogClaimUri.Query)
{
return false;
}
if (Log.IsDebugEnabled)
{
Log.Debug("SetAuthenticationTicket-Admins via OpenID for " + currentBlog.UserName);
}
HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);
httpContext.SetAuthenticationTicket(currentBlog, currentBlog.UserName, persist, "Admins");
return true;
}
示例3: AuthenticateHostAdmin
/// <summary>
/// Authenticates the host admin.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
/// <param name="persist">if set to <c>true</c> [persist].</param>
/// <returns></returns>
public static bool AuthenticateHostAdmin(string username, string password, bool persist)
{
if(!String.Equals(username, HostInfo.Instance.HostUserName, StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if(Config.Settings.UseHashedPasswords)
{
password = HashPassword(password, HostInfo.Instance.Salt);
}
if(!String.Equals(HostInfo.Instance.Password, password, StringComparison.InvariantCultureIgnoreCase))
{
return false;
}
if(Log.IsDebugEnabled)
{
Log.Debug("SetAuthenticationTicket-HostAdmins for " + username);
}
HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);
httpContext.SetAuthenticationTicket(null, username, persist, true, "HostAdmins");
return true;
}