/// <summary> /// Used to remove a cookie from the client. /// </summary> /// <returns>a correctly named cookie with Expires date set 30 years ago</returns> public static HttpCookie GetExpiredCookie(this HttpRequestBase request, Blog blog) { var expiredCookie = new HttpCookie(request.GetFullCookieName(blog)) { Expires = DateTime.UtcNow.AddYears(-30) }; return(expiredCookie); }
/// <summary> /// Obtains the correct cookie for the current blog /// </summary> /// <returns>null if correct cookie was not found</returns> public static HttpCookie SelectAuthenticationCookie(this HttpRequestBase request, Blog blog) { HttpCookie authCookie = null; HttpCookie c; int count = request.Cookies.Count; for (int i = 0; i < count; i++) { c = request.Cookies[i]; if (c.Name == request.GetFullCookieName(blog)) { authCookie = c; break; } } return(authCookie); }
private static void LogoutCookie(HttpResponseBase response, HttpRequestBase request, Blog blog) { var cookieName = request.GetFullCookieName(blog); if (request.Cookies[cookieName] != null) { var authCookie = new HttpCookie(cookieName) { HttpOnly = true, Expires = DateTime.UtcNow.AddYears(-30), Value = request.Browser == null || request.Browser["supportsEmptyStringInCookieValue"] == "false" ? "Empty" : String.Empty }; request.Cookies.Remove(cookieName); response.Cookies.Add(authCookie); } }
/// <summary> /// Identifies cookies by unique BlogHost names (rather than a single /// name for all cookies in multiblog setups as the old code did). /// </summary> /// <returns></returns> public static string GetFullCookieName(this HttpRequestBase request, Blog blog) { return(request.GetFullCookieName(blog, forceHostAdmin: (blog == null || blog.IsAggregateBlog))); }