/// <summary> /// Sets the basic auth cookie. /// </summary> /// <param name="value">The value.</param> /// <param name="expires">The expires.</param> internal static void SetBasicAuthCookie(string value, int expires) { string cookieName = BasicAuthenticationHelper.CookieName; if (!string.IsNullOrEmpty(cookieName)) { HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName] ?? new HttpCookie(cookieName); cookie.Value = AuthenticationEncryption.Encrypt(value); cookie.Expires = DateTime.Now.AddMinutes(expires); HttpContext.Current.Response.Cookies.Add(cookie); } }
/// <summary> /// Gets the basic auth cookie. /// </summary> /// <returns></returns> internal static string GetBasicAuthCookie() { try { string cookieName = BasicAuthenticationHelper.CookieName; if (!string.IsNullOrEmpty(cookieName)) { if (HttpContext.Current.Request.Cookies[cookieName] != null && !string.IsNullOrEmpty(HttpContext.Current.Request.Cookies[cookieName].Value)) { return (AuthenticationEncryption.Decrypt( HttpContext.Current.Request.Cookies[cookieName].Value)); } } } catch (Exception ex) { ApplicationException aex = new ApplicationException("Crafted.Volva.CookieHelper.GetAuthCookie() threw an unhandled exception.", ex); //Logging.LogError(aex); return(String.Empty); } return(String.Empty); }