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
0
 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
0
    public static void SetCookie(this System.Web.HttpResponseBase response, string name, string value, DateTime?expires = null, string path = "/")
    {
        var cookie = new System.Web.HttpCookie(name, value);

        if (expires.HasValue)
        {
            cookie.Expires = expires.Value;
        }
        cookie.Path = path;
        response.SetCookie(cookie);
    }
Пример #4
0
        /// <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);
        }
        /// <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);
        }
Пример #6
0
        public static void SetCookie(this HttpResponseBase response, string key, string value, string domain = null, bool httpOnly = false, DateTime?expires = null)
        {
            if (response == null)
            {
                return;
            }
            var cookie = new HttpCookie(key, value);

            cookie.HttpOnly = httpOnly;
            if (expires.HasValue)
            {
                cookie.Expires = expires.Value;
            }
            if (!string.IsNullOrEmpty(domain))
            {
                cookie.Domain = domain;
            }
            response.SetCookie(cookie);
        }
Пример #7
0
        public void Logout(System.Web.HttpRequestBase request, System.Web.HttpResponseBase response, System.Web.HttpSessionStateBase session)
        {
            HttpCookie myCookie = new HttpCookie("rfs.username");

            myCookie = request.Cookies["rfs.username"];
            if (myCookie != null)
            {
                session[myCookie.Value] = "";
            }

            HttpCookie currentUserCookie = request.Cookies["rfs.username"];

            response.Cookies.Remove("rfs.username");
            if (currentUserCookie != null)
            {
                currentUserCookie.Expires = DateTime.Now.AddDays(-10);
                currentUserCookie.Value   = null;
                response.SetCookie(currentUserCookie);
            }
        }
Пример #8
0
        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);
        }
        /// <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
0
 public void SetUserMode(HttpResponseBase response, UserMode userMode)
 {
     HttpCookie modeCookie = new HttpCookie("CurrentMode", userMode.ToString());
     response.SetCookie(modeCookie);
 }
Пример #11
0
 public static void RemoveMessage(HttpResponseBase response)
 {
     HttpCookie cookie = new HttpCookie("SystemMessage");
     cookie.Expires = DateTime.Now.AddDays(-1);
     response.SetCookie(cookie);
 }
        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);
            }
        }
Пример #13
0
 public void AuthenticateUser(HttpResponseBase response)
 {
     var token = protector.Protect(this.AuthToken());
     response.SetCookie(new HttpCookie(cookieid, token));
 }
        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);
        }
Пример #15
0
		public void ClearCookie(HttpResponseBase resp)
		{
			if (resp == null) throw new ArgumentNullException("resp");
			resp.SetCookie(new HttpCookie(CookieName, null) { Expires = new DateTime(2010,1,1) });
		}
Пример #16
0
 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)));
 }
Пример #17
0
        public void Save(HttpResponseBase response)
        {
            var cookie = ToHttpCookie();
            cookie.Expires = DateTime.UtcNow.AddYears(10);

            response.SetCookie(cookie);
        }
        /// <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)
                });
            }
        }