本文整理汇总了C#中IMansionContext.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:C# IMansionContext.SetCookie方法的具体用法?C# IMansionContext.SetCookie怎么用?C# IMansionContext.SetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMansionContext
的用法示例。
在下文中一共展示了IMansionContext.SetCookie方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoExecute
/// <summary>
/// Executes this tag.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
protected override void DoExecute(IMansionContext context)
{
// create the cookie
var cookie = new WebCookie {
Name = GetRequiredAttribute<string>(context, "name"),
HttpOnly = GetAttribute(context, "httpOnly", true),
Expires = GetAttribute(context, "expires", DateTime.Today.AddDays(30)),
Value = GetRequiredAttribute<string>(context, "value")
};
// set the cookie
context.SetCookie(cookie);
}
示例2: 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;
}