SetCookie() public method

public SetCookie ( System.Web.HttpCookie cookie ) : void
cookie System.Web.HttpCookie
return void
Example #1
0
 /// <summary>
 /// Copy cookies from the inbound response to the outbound response
 /// </summary>
 /// <param name="source">Reply from the intended destination</param>
 /// <param name="destination">response being sent back to the ajax request</param>
 public static void CopyCookiesTo(this HttpWebResponse source, HttpResponse destination)
 {
     foreach (HttpCookie cookie in source.Cookies)
     {
         destination.SetCookie(new HttpCookie(cookie.Name, cookie.Value));
     }
 }
Example #2
0
        private void SetCartGuid(string guid, HttpResponse response)
        {
            if (response == null)
                return;

            HttpCookie cookie = new HttpCookie(BXSaleCart.ExternalStorageUIDKey, guid);
            cookie.Expires = DateTime.Now.AddYears(1);
            response.SetCookie(cookie);
        }
 public void Logout(HttpResponse httpResponse)
 {
     HttpCookie authCookie = httpResponse.Cookies[FormsAuthentication.FormsCookieName];
     if (authCookie != null)
     {
         authCookie.Expires = DateTime.Now.AddDays(-1);
         authCookie.Value = null;
         httpResponse.Cookies.Remove(FormsAuthentication.FormsCookieName);
         httpResponse.SetCookie(authCookie);
     }
 }
        public static void SetCookie(this HttpResponse 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);
        }
        public void ProlongateUserSession(HttpResponse httpResponse, CustomPrincipalSerializeModel principalModel)
        {
            string userData = JsonConvert.SerializeObject(principalModel);
            var expirationTime = DateTime.Now.AddMinutes(15);

            var authTicket = new FormsAuthenticationTicket(
                1,
                principalModel.Login,
                DateTime.Now,
                expirationTime,
                false, // pass here true, if you want to implement remember me functionality
                userData);

            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            httpResponse.Cookies.Remove(FormsAuthentication.FormsCookieName);
            httpResponse.SetCookie(cookie);
        }
Example #6
0
        public static void SetTrafficSheetCookie(string sessionID, System.Web.HttpResponse response, Entities.TrafficSheetFilter filter)
        {
            HttpCookie tSheetCookie = new HttpCookie(sessionID);
            string     trafficSheetFilterJSON;


            trafficSheetFilterJSON = JsonConvert.SerializeObject(filter);


            tSheetCookie[C_TRAFFIC_SHEET_JSON] = trafficSheetFilterJSON;

            // Settings option to have the cookie expire daily or never
            if (Orchestrator.Globals.Configuration.ResetTrafficCookieDaily)
            {
                tSheetCookie.Expires = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59);
            }
            else
            {
                tSheetCookie.Expires = new DateTime(2099, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59);
            }

            response.SetCookie(tSheetCookie);
        }
Example #7
0
		public static void Deauthenticate(HttpResponse Response)
		{
			//Response.Cookies.Remove("Remember");
			//Response.Cookies.Remove("RememberUserName");
			//Response.Cookies.Remove("Cooked");

			//Response.Cookies.Set(new HttpCookie("Remember", ""));
			//Response.Cookies.Set(new HttpCookie("RememberUserName", ""));
			//Response.Cookies.Set(new HttpCookie("Cooked", ""));
			Response.SetCookie(new HttpCookie("Remember", ""));
			Response.SetCookie(new HttpCookie("RememberUserName", ""));
			Response.SetCookie(new HttpCookie("Cooked", ""));
			ClearLastHash();
		}
 public override void SetCookie(HttpCookie cookie)
 {
     _httpResponse.SetCookie(cookie);
 }
Example #9
0
		public void Methods_Deny_Unrestricted ()
		{
			HttpResponse response = new HttpResponse (writer);
			response.AddCacheItemDependencies (new ArrayList ());
			response.AddCacheItemDependency (String.Empty);
			response.AddFileDependencies (new ArrayList ());
			response.AddFileDependency (fname);
			response.AddCacheDependency (new CacheDependency[0]);
			response.AddCacheItemDependencies (new string [0]);
			response.AddFileDependencies (new string [0]);

			try {
				response.AppendCookie (new HttpCookie ("mono"));
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				Assert.IsNull (response.ApplyAppPathModifier (null), "ApplyAppPathModifier");
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.Clear ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		
			try {
				response.ClearContent ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		
			try {
				response.ClearHeaders ();
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.Redirect ("http://www.mono-project.com");
			}
			catch (NullReferenceException) {
				// ms 
			}
			try {
				response.Redirect ("http://www.mono-project.com", false);
			}
			catch (NullReferenceException) {
				// ms 
			}

			try {
				response.SetCookie (new HttpCookie ("mono"));
			}
			catch (NullReferenceException) {
				// ms 
			}

			response.Write (String.Empty);
			response.Write (Char.MinValue);
			response.Write (new char[0], 0, 0);
			response.Write (this);
			response.WriteSubstitution (new HttpResponseSubstitutionCallback (Callback));

			response.Flush ();

			response.Close ();

			try {
				response.End ();
			}
			catch (NullReferenceException) {
				// ms 
			}
		}
Example #10
0
 public override void SetCookie(HttpCookie cookie)
 {
     w.SetCookie(cookie);
 }
 private void UpdateProfile(HttpResponse response, IMarket market)
 {
     var cookie = response.Cookies[_marketIdKey];
     var originalMarketId = cookie == null ? string.Empty : cookie.Value;
     var currentMarketId = market == null || market.MarketId == MarketId.Default ? string.Empty : market.MarketId.Value;
     if (!string.Equals(originalMarketId, currentMarketId, StringComparison.Ordinal))
     {
         cookie = new HttpCookie(_marketIdKey, currentMarketId);
         response.SetCookie(cookie);
     }
 }
Example #12
0
 public static void RemoveMessage(HttpResponse response)
 {
     HttpCookie cookie = new HttpCookie("SystemMessage");
     cookie.Expires = DateTime.Now.AddDays(-1);
     response.SetCookie(cookie);
 }
Example #13
0
 public static void CreateMessage(MessageType messageType, string messageTitle, List<string> messageDetails, HttpResponse response)
 {
     MessageModel message = new MessageModel(messageType, messageTitle, messageDetails);
     response.SetCookie(new HttpCookie("SystemMessage", SerializationHelper.Serialization<MessageModel>(message)));
 }