本文整理汇总了C#中IMansionContext.DeleteCookie方法的典型用法代码示例。如果您正苦于以下问题:C# IMansionContext.DeleteCookie方法的具体用法?C# IMansionContext.DeleteCookie怎么用?C# IMansionContext.DeleteCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMansionContext
的用法示例。
在下文中一共展示了IMansionContext.DeleteCookie方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoExecute
/// <summary>
/// Executes this tag.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
protected override void DoExecute(IMansionContext context)
{
// clear the cookie
context.DeleteCookie(GetRequiredAttribute<string>(context, "name"));
}
示例2: InitializeUserFromCookie
/// <summary>
/// Tries to revive the user from cookie.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="cookieName">The name of the cookie from which to revive the user.</param>
/// <returns>Returns the revived user or null.</returns>
private UserState InitializeUserFromCookie(IMansionContext context, string cookieName)
{
// get the web request context
var webContext = context.Cast<IMansionWebContext>();
// check sesssion
if (!webContext.Session.IsReadable)
return null;
var sessionUser = webContext.Session[cookieName] as UserState;
if (sessionUser != null)
return sessionUser;
// check for revival cookie
WebCookie revivalCookie;
if (!webContext.Request.Cookies.TryGetValue(cookieName, out revivalCookie) || string.IsNullOrEmpty(revivalCookie.Value))
return null;
// deserialize the properties
var revivalDataStringBytes = conversionService.Convert<byte[]>(context, revivalCookie.Value);
byte[] decryptedRevivalDataBytes;
try
{
decryptedRevivalDataBytes = encryptionService.Decrypt(context, cookieSalt, revivalDataStringBytes);
}
catch (CryptographicException)
{
// cookie contains invalid hash
context.DeleteCookie(cookieName);
return null;
}
var revivalProperties = conversionService.Convert<IPropertyBag>(context, decryptedRevivalDataBytes, new PropertyBag());
// check against cookie theft
var currentUserSignature = GetUserSignatureHash(webContext);
var cookieUserSignature = revivalProperties.Get(context, "userSignature", string.Empty);
if (!cookieUserSignature.Equals(currentUserSignature))
{
context.DeleteCookie(cookieName);
return null;
}
// get the authentication provider
String authenticationProviderName;
if (!revivalProperties.TryGetAndRemove(context, "authenticationProviderName", out authenticationProviderName) || string.IsNullOrEmpty(authenticationProviderName))
{
context.DeleteCookie(cookieName);
return null;
}
AuthenticationProvider authenticationProvider;
if (!TryResolveAuthenticationProvider(context, authenticationProviderName, out authenticationProvider))
{
context.DeleteCookie(cookieName);
return null;
}
// try to revive the user
var revivedUser = authenticationProvider.ReviveUser(context, revivalProperties);
if (revivedUser == null)
context.DeleteCookie(cookieName);
return revivedUser;
}
示例3: DoAuthenticate
/// <summary>
/// Authenticates the user.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="authenicationProvider">The authentication provider which to use.</param>
/// <param name="parameters">The parameters used for authentication.</param>
/// <returns>Returns the <see cref="AuthenticationResult"/>.</returns>
protected override AuthenticationResult DoAuthenticate(IMansionContext context, AuthenticationProvider authenicationProvider, IPropertyBag parameters)
{
// authenticate
var result = authenicationProvider.Authenticate(context, parameters);
if (!result.WasSuccesful)
return result;
var user = result.UserState;
// get the web request context
var webContext = context.Cast<IMansionWebContext>();
// check session
if (!webContext.Session.IsWritable)
throw new InvalidOperationException("Could not authenticate user because the session is not writeable");
// store this user in the session
webContext.Session[GetRevivalCookieName(context)] = user;
// check if the authentication provider support user revival and the rememberMe flag was set
var revivalCookieName = GetRevivalCookieName(context);
if (authenicationProvider.SupportsRevival && parameters.Get(context, "allowRevival", false))
{
// get the revival data for this user
var revivalData = authenicationProvider.GetRevivalProperties(context, user, parameters);
if (revivalData != null)
{
// add additional revival properties
revivalData.Set("authenticationProviderName", authenicationProvider.Name);
revivalData.Set("userSignature", GetUserSignatureHash(webContext));
// encrypt it
var serializedRevivalData = conversionService.Convert<byte[]>(context, revivalData);
var encryptedRevivalData = encryptionService.Encrypt(context, cookieSalt, serializedRevivalData);
var revivalDataString = conversionService.Convert<string>(context, encryptedRevivalData);
// store it in a cookie
var revivalCookie = new WebCookie {
Name = revivalCookieName,
Value = revivalDataString,
Expires = DateTime.Now.AddDays(14),
HttpOnly = true
};
context.SetCookie(revivalCookie);
}
}
else
context.DeleteCookie(revivalCookieName);
// authentication was successful
return result;
}
示例4: DoLogoff
/// <summary>
/// Logs the user of from the current request context.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="authenicationProvider">The authentication provider which to use.</param>
protected override void DoLogoff(IMansionContext context, AuthenticationProvider authenicationProvider)
{
// authenticate
authenicationProvider.Logoff(context);
// get the web request context
var webContext = context.Cast<IMansionWebContext>();
// check session
if (!webContext.Session.IsWritable)
throw new InvalidOperationException("Could not log off user because the session is not writeable");
// clear the user from the session
webContext.Session.Remove(GetRevivalCookieName(context));
// delete any revival cookies
context.DeleteCookie(GetRevivalCookieName(context));
}