本文整理汇总了C#中System.Net.Cookie.ToCookieString方法的典型用法代码示例。如果您正苦于以下问题:C# Cookie.ToCookieString方法的具体用法?C# Cookie.ToCookieString怎么用?C# Cookie.ToCookieString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Cookie
的用法示例。
在下文中一共展示了Cookie.ToCookieString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoginRequest
/// <summary>
/// Tries to log a user in.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
/// <param name="search">The search part of the location where to redirect to on success.</param>
/// <returns></returns>
public Response LoginRequest(string username, string password, string search)
{
int userID = Proxy.SessionManager.UserID(username);
if (userID == -1)
{
return PageWithErrorMessage("login.html", "wrong_username", "Username does not exist.", username);
}
else if (!Proxy.SessionManager.IsCorrectPW(username, password))
{
return PageWithErrorMessage("login.html", "wrong_password", "Password is incorrect.", username);
}
// User+PW correct
Logger.Metric(userID, "Login.");
Proxy.SessionManager.LogUserIn(ClientIP, userID);
// Set cookies.
Cookie idCookie = new Cookie("uid", "" + userID, "/");
Cookie nameCookie = new Cookie("uname", username, "/");
DateTime expiryDate = Proxy.SessionManager.GetSessionExpiryDate(userID);
idCookie.Expires = expiryDate;
nameCookie.Expires = expiryDate;
// We must use Headers.Add (Not AddHeader, not SetCookie and not AppendCookie)
// as in the other cases only a comma separated list in one Set-Cookie would be created,
// which browsers do not understand. C# sucks.
_clientHttpContext.Response.Headers.Add("Set-Cookie", idCookie.ToCookieString());
_clientHttpContext.Response.Headers.Add("Set-Cookie", nameCookie.ToCookieString());
// Redirect to the User Homepage.
_clientHttpContext.Response.Redirect("/trotro-user.html" + search);
return new Response();
}
示例2: SendLogoutCookies
/// <summary>
/// Sends expired cookies, so they will be deleted at the client side.
/// </summary>
private void SendLogoutCookies()
{
// Set cookies.
Cookie idCookie = new Cookie("uid", "", "/");
Cookie nameCookie = new Cookie("uname", "", "/");
Cookie statusCookie = new Cookie("status", "", "/");
// Expiry date in the past.
DateTime expiryDate = DateTime.Now.AddDays(-1);
idCookie.Expires = expiryDate;
nameCookie.Expires = expiryDate;
statusCookie.Expires = expiryDate;
_clientHttpContext.Response.Headers.Add("Set-Cookie", idCookie.ToCookieString());
_clientHttpContext.Response.Headers.Add("Set-Cookie", nameCookie.ToCookieString());
_clientHttpContext.Response.Headers.Add("Set-Cookie", statusCookie.ToCookieString());
}