本文整理汇总了C#中System.Web.HttpResponseBase.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseBase.SetCookie方法的具体用法?C# HttpResponseBase.SetCookie怎么用?C# HttpResponseBase.SetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponseBase
的用法示例。
在下文中一共展示了HttpResponseBase.SetCookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetCurrentCultureCookie
public static void SetCurrentCultureCookie(HttpResponseBase response, string cultureName)
{
if (_s_supportedCultures.Any(item => item.Value == cultureName))
{
response.SetCookie(new HttpCookie(CultureCookieName, cultureName) { HttpOnly = true });
}
}
示例2: SetKey
public void SetKey(HttpRequestBase request, HttpResponseBase response, string sessionKey)
{
var cookie = new HttpCookie("sessionId", sessionKey);
cookie.Expires = DateTime.Now.AddMinutes(15);
cookie.Path = "/";
response.SetCookie(cookie);
}
示例3: ManageLanguageCookie
/// <summary>
/// This takes the language code (from url) and makes sure the cookie is set accordingly.
/// </summary>
/// <param name="langCode"></param>
/// <param name="response"></param>
/// <returns></returns>
public static void ManageLanguageCookie(string langCode, HttpResponseBase response)
{
// Get the cookie
var languageCookie = HttpContext.Current.Request.Cookies["Language"];
if (languageCookie == null)
{
languageCookie = new HttpCookie("Language"); // Create if needed
}
languageCookie.Value = langCode;
languageCookie.Expires = DateTime.Now.AddDays(10);
response.SetCookie(languageCookie);
}
示例4: SetCookie
/// <summary>
/// Creates or updates a cookie in the cookie collection.
/// </summary>
/// <param name="httpResponse">The HTTP response to set the cookie for.</param>
/// <param name="cookieName">The name of the cookie.</param>
/// <param name="cookieValue">The value of the cookie.</param>
/// <exception cref="ArgumentNullException"><paramref name="httpResponse"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException"><paramref name="cookieName"/> is <c>null</c>, empty, or white space.</exception>
public static void SetCookie(HttpResponseBase httpResponse, string cookieName, string cookieValue)
{
/* TODO Parameterize the cookie expiration date (now hard-coded to 1 year).
* Steven Volckaert. January 16, 2013.
*/
if (httpResponse == null)
throw new ArgumentNullException("httpResponse");
if (String.IsNullOrWhiteSpace(cookieName))
throw new ArgumentException("The parameter is null or empty.", "cookieName");
var cookie = string.IsNullOrEmpty(cookieValue)
? new HttpCookie(cookieName)
: new HttpCookie(cookieName, cookieValue);
cookie.Expires = DateTime.Now.AddYears(1);
httpResponse.SetCookie(cookie);
}
示例5: SetAuthCooke
public static void SetAuthCooke(HttpResponseBase response, int userId, string guid, int minutes = 60)
{
if(userId < 1 || guid == null)
{
return;
}
var cookie = new HttpCookie(Constants.COOKIE_AUTH)
{
Value = Helpers.CEncode(guid + ":" + userId),
Expires = DateTime.Now.AddMinutes(minutes)
};
response.SetCookie(cookie);
}
示例6: SetUserMode
public void SetUserMode(HttpResponseBase response, UserMode userMode)
{
HttpCookie modeCookie = new HttpCookie("CurrentMode", userMode.ToString());
response.SetCookie(modeCookie);
}
示例7: AuthenticateUser
public void AuthenticateUser(HttpResponseBase response)
{
var token = protector.Protect(this.AuthToken());
response.SetCookie(new HttpCookie(cookieid, token));
}
示例8: ClearCookie
public void ClearCookie(HttpResponseBase resp)
{
if (resp == null) throw new ArgumentNullException("resp");
resp.SetCookie(new HttpCookie(CookieName, null) { Expires = new DateTime(2010,1,1) });
}
示例9: ApplyCookies
/// <summary>
/// Apply cookies of the CommandResult to the response.
/// </summary>
/// <param name="commandResult">Commandresult</param>
/// <param name="response">Response</param>
public static void ApplyCookies(this CommandResult commandResult, HttpResponseBase response)
{
if(commandResult == null)
{
throw new ArgumentNullException(nameof(commandResult));
}
if(response == null)
{
throw new ArgumentNullException(nameof(response));
}
if (!string.IsNullOrEmpty(commandResult.SetCookieName))
{
var protectedData = HttpRequestData.ConvertBinaryData(
MachineKey.Protect(
commandResult.GetSerializedRequestState(),
HttpRequestBaseExtensions.ProtectionPurpose));
response.SetCookie(new HttpCookie(
commandResult.SetCookieName,
protectedData)
{
HttpOnly = true
});
}
if (!string.IsNullOrEmpty(commandResult.ClearCookieName))
{
response.SetCookie(new HttpCookie(commandResult.ClearCookieName)
{
Expires = new DateTime(1970, 01, 01)
});
}
}
示例10: Save
public void Save(HttpResponseBase response)
{
var cookie = ToHttpCookie();
cookie.Expires = DateTime.UtcNow.AddYears(10);
response.SetCookie(cookie);
}
示例11: ApplyCookies
/// <summary>
/// Apply cookies of the CommandResult to the response.
/// </summary>
/// <param name="commandResult">Commandresult</param>
/// <param name="response">Response</param>
public static void ApplyCookies(this CommandResult commandResult, HttpResponseBase response)
{
if(commandResult == null)
{
throw new ArgumentNullException(nameof(commandResult));
}
if(response == null)
{
throw new ArgumentNullException(nameof(response));
}
if (!string.IsNullOrEmpty(commandResult.SetCookieName))
{
var protectedData = HttpRequestData.EscapeBase64CookieValue(
Convert.ToBase64String(
MachineKey.Protect(
Encoding.UTF8.GetBytes(commandResult.SetCookieData),
"Kentor.AuthServices")));
response.SetCookie(new HttpCookie(
commandResult.SetCookieName,
protectedData)
{
HttpOnly = true
});
}
if (!string.IsNullOrEmpty(commandResult.ClearCookieName))
{
response.SetCookie(new HttpCookie(commandResult.ClearCookieName)
{
Expires = new DateTime(1970, 01, 01)
});
}
}
示例12: UpdateAuthCookie
protected void UpdateAuthCookie(HttpResponseBase Response, HttpCookie cookie)
{
SimpleAuthenticationTicket ticket = SimpleAuthenticationTicket.Decrypt(cookie.Value);
if (ticket == null)
{
return;
}
//Если KeepLoggedIn, то продляем
if (ticket.KeepLoggedIn)
{
ticket.ExpirationDate = DateTime.Now.AddDays(SettingsManager.AuthenticationSettings.DaysToExpiration);
cookie.Expires = ticket.ExpirationDate;
}
cookie.Value = ticket.Encrypt();
Response.SetCookie(cookie);
}
示例13: SetCookies
public void SetCookies(HttpResponseBase Response, User User, bool KeepLoggedIn)
{
HttpCookie cookie = CreateAuthCookie(User, KeepLoggedIn);
Response.SetCookie(cookie);
cookie = CreateSessionCookie(User);
if (cookie != null)
{
Response.SetCookie(cookie);
}
}
示例14: RemoveMessage
public static void RemoveMessage(HttpResponseBase response)
{
HttpCookie cookie = new HttpCookie("SystemMessage");
cookie.Expires = DateTime.Now.AddDays(-1);
response.SetCookie(cookie);
}
示例15: CreateMessage
public static void CreateMessage(MessageType messageType, string messageTitle, List<string> messageDetails, HttpResponseBase response)
{
MessageModel message = new MessageModel(messageType, messageTitle, messageDetails);
response.SetCookie(new HttpCookie("SystemMessage", SerializationHelper.Serialization<MessageModel>(message)));
}