public void DuplicateNames ()
		{
			HttpCookieCollection col = new HttpCookieCollection ();
			HttpCookie cookie1 = new HttpCookie ("cookie", "value1");
			HttpCookie cookie2 = new HttpCookie ("cookie", "value2");

			col.Add (cookie1);
			col.Add (cookie2);

			Assert.AreEqual ("value1", col["cookie"].Value, "add should use first used cookie");

			col.Set (cookie2);
			Assert.AreEqual ("value2", col["cookie"].Value, "set should use last used cookie");

			col.Clear ();
			col.Add (cookie1);
			col.Add (cookie2);

			// Bug #553150
			HttpCookie tmp = col.Get (0);
			Assert.AreEqual ("cookie", tmp.Name, "#A1");
			Assert.AreEqual ("value1", tmp.Value, "#A1-1");

			tmp = col.Get (1);
			Assert.AreEqual ("cookie", tmp.Name, "#A2");
			Assert.AreEqual ("value2", tmp.Value, "#A2-1");
		}
Beispiel #2
0
		public void Deny_Unrestricted ()
		{
			HttpCookieCollection jar = new HttpCookieCollection ();
			jar.Add (biscuit);
			jar.CopyTo (new object[1], 0);
			Assert.IsNull (jar.GetKey (0), "GetKey");
			jar.Remove ("chocolat");
			jar.Set (biscuit);
			Assert.IsNotNull (jar.Get (0), "Get(int)");
			Assert.IsNull (jar.Get ("chocolat"), "Get(string)");
			Assert.IsNotNull (jar[0], "this[int]");
			Assert.IsNull (jar["chocolat"], "this[string]");
			Assert.AreEqual (1, jar.AllKeys.Length, "AllKeys");
			jar.Clear ();
		}
 internal void Add ( HttpCookieCollection c )
 {
     int count = c.Count;
     for ( int i = 0 ; i < count ; i++ )
     {
         HttpCookie cookie = c.Get ( i );
         base.Add ( cookie.Name , cookie.Value );
     }
 }
Beispiel #4
0
 /// <summary>
 /// Converts an HttpCookieCollection into parameters
 /// </summary>
 /// <param name="cookies">An HttpCookieCollection</param>
 public void Add(HttpCookieCollection cookies)
 {
     var count = cookies.Count;
     for(var index = 0; index < count; index++)
     {
         var cookie = cookies.Get(index);
         Add(cookie.Name, cookie.Value);
     }
 }
        internal void Add(HttpCookieCollection c)
        {
            int n = c.Count;

            for (int i = 0; i < n; i++)
            {
                HttpCookie cookie = c.Get(i);
                Add(cookie.Name, cookie.Value);
            }
        }
        private static string GetCookie(string cookieName, System.Web.HttpCookieCollection cookieCollection)
        {
            var cookie = cookieCollection?.Get(cookieName);

            if (cookie == null)
            {
                return(string.Empty);
            }
            return(cookieCollection[cookieName].Value);
        }
Beispiel #7
0
        public static void ForgetLoggedInUser(HttpCookieCollection requestCookies, HttpCookieCollection responseCookies)
        {
            DeleteRememberedSession(requestCookies);

            var cookie = responseCookies.Get(CookieName);
            cookie.Path = HttpContext.Current.Request.ApplicationPath;
            cookie.Expires = DateTime.Now;
            cookie.Value = "";
            responseCookies.Set(cookie);
        }
 internal void Add(HttpCookieCollection c)
 {
     int count = c.Count;
     for (int i = 0; i < count; i++)
     {
         this.ThrowIfMaxHttpCollectionKeysExceeded();
         HttpCookie cookie = c.Get(i);
         base.Add(cookie.Name, cookie.Value);
     }
 }
        internal void Add(HttpCookieCollection c)
        {
            int n = c.Count;

            for (int i = 0; i < n; i++)
            {
                ThrowIfMaxHttpCollectionKeysExceeded();
                HttpCookie cookie = c.Get(i);
                base.Add(cookie.Name, cookie.Value);
            }
        }
        private string Gets(HttpCookieCollection cookies)
        {
            var containsCookie = cookies.AllKeys.Contains(_cookieName);
            if (!containsCookie)
            {
                return null;
            }

            var cookie = cookies.Get(_cookieName);
            return cookie != null ? cookie.Value : null;
        }
Beispiel #11
0
 public static NameValueCollection CreateParams(NameValueCollection queryString, NameValueCollection form, HttpCookieCollection cookies, NameValueCollection serverVariables)
 {
     NameValueCollection parms = new NameValueCollection(48);
     parms.Add(queryString);
     parms.Add(form);
     for (var i = 0; i < cookies.Count; i++)
     {
         var cookie = cookies.Get(i);
         parms.Add(cookie.Name, cookie.Value);
     }
     parms.Add(serverVariables);
     return parms;
 }
            public CookieValueProvider(HttpCookieCollection cookieCollection)
            {
                foreach (string cookieName in cookieCollection)
                {
                    var cookie = cookieCollection.Get(cookieName);

                    foreach (var key in cookie.Values.AllKeys)
                    {
                        if (key != null)
                            _cookiesKeys.Add(key, cookie.Values.Get(key));
                    }
                }
            }
Beispiel #13
0
 private static RememberedSessions TryGetRememberedSession(EpidaurusDbContainer db, HttpCookieCollection requestCookies)
 {
     var cookie = requestCookies.Get(CookieName);
     if (cookie == null || string.IsNullOrEmpty(cookie.Value))
         return null;
     var match = Regex.Match(cookie.Value, @"^(.+)_([0-9a-f-]+)$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
     if (!match.Success)
         return null;
     string userName = match.Groups[1].Value;
     Guid guid;
     if (!Guid.TryParse(match.Groups[2].Value, out guid))
         return null;
     string guidStr = guid.ToString();
     return db.RememberedSessions.FirstOrDefault(el => el.User.Username == userName && el.GuidHash == guidStr);
 }
Beispiel #14
0
        // Generate:
        //   Content-Length
        //   Content-Type
        //   Transfer-Encoding (chunked)
        //   Cache-Control
        //   X-AspNet-Version
        void AddHeadersNoCache(NameValueCollection write_headers, bool final_flush)
        {
            //
            // Transfer-Encoding
            //
            if (use_chunked)
            {
                write_headers.Add("Transfer-Encoding", "chunked");
            }
            else if (transfer_encoding != null)
            {
                write_headers.Add("Transfer-Encoding", transfer_encoding);
            }
            if (redirect_location != null)
            {
                write_headers.Add("Location", redirect_location);
            }

            string vh = VersionHeader;

            if (vh != null)
            {
                write_headers.Add("X-AspNet-Version", vh);
            }

            //
            // If Content-Length is set.
            //
            if (content_length >= 0)
            {
                write_headers.Add(HttpWorkerRequest.GetKnownResponseHeaderName(HttpWorkerRequest.HeaderContentLength),
                                  content_length.ToString(Helpers.InvariantCulture));
            }
            else if (BufferOutput)
            {
                if (final_flush)
                {
                    //
                    // If we are buffering and this is the last flush, not a middle-flush,
                    // we know the content-length.
                    //
                    content_length = output_stream.total;
                    write_headers.Add(HttpWorkerRequest.GetKnownResponseHeaderName(HttpWorkerRequest.HeaderContentLength),
                                      content_length.ToString(Helpers.InvariantCulture));
                }
                else
                {
                    //
                    // We are buffering, and this is a flush in the middle.
                    // If we are not chunked, we need to set "Connection: close".
                    //
                    if (use_chunked)
                    {
                        write_headers.Add(HttpWorkerRequest.GetKnownResponseHeaderName(HttpWorkerRequest.HeaderConnection), "close");
                    }
                }
            }
            else
            {
                //
                // If the content-length is not set, and we are not buffering, we must
                // close at the end.
                //
                if (use_chunked)
                {
                    write_headers.Add(HttpWorkerRequest.GetKnownResponseHeaderName(HttpWorkerRequest.HeaderConnection), "close");
                }
            }

            //
            // Cache Control, the cache policy takes precedence over the cache_control property.
            //
            if (cache_policy != null)
            {
                cache_policy.SetHeaders(this, headers);
            }
            else
            {
                write_headers.Add("Cache-Control", CacheControl);
            }

            //
            // Content-Type
            //
            if (content_type != null)
            {
                string header = content_type;

                if (charset_set || header == "text/plain" || header == "text/html")
                {
                    if (header.IndexOf("charset=") == -1 && !string.IsNullOrEmpty(charset))
                    {
                        header += "; charset=" + charset;
                    }
                }

                write_headers.Add("Content-Type", header);
            }

            if (cookies != null && cookies.Count != 0)
            {
                int n = cookies.Count;
                for (int i = 0; i < n; i++)
                {
                    write_headers.Add("Set-Cookie", cookies.Get(i).GetCookieHeaderValue());
                }
            }
        }
Beispiel #15
0
        private void Add(NameValueCollection collection,  HttpCookieCollection c) {
            int n = c.Count;

            for(int i = 0; i < n; i++) {
                HttpCookie cookie = c.Get(i);
                collection.Add(cookie.Name, cookie.Value);
            }
        } 
 internal void Add(HttpCookieCollection c)
 {
     int num1 = c.Count;
       for (int num2 = 0; num2 < num1; num2++)
       {
     HttpCookie cookie1 = c.Get(num2);
     base.Add(cookie1.Name, cookie1.Value);
       }
 }
 private void ValidateCookieCollection(HttpCookieCollection cc)
 {
     int count = cc.Count;
     for (int i = 0; i < count; i++)
     {
         string key = cc.GetKey(i);
         string str2 = cc.Get(i).Value;
         if (!string.IsNullOrEmpty(str2))
         {
             this.ValidateString(str2, key, RequestValidationSource.Cookies);
         }
     }
 }
Beispiel #18
0
		public void UpdateTest ()
		{
			// the msdn examples show updates with col.Set being
			// called after a change is made to a cookie.  turns
			// out this isn't necessary.

			HttpCookieCollection col = new HttpCookieCollection ();
			HttpCookie cookie1, cookie2;

			cookie1 = new HttpCookie ("cookie", "value1");

			col.Add (cookie1);

			cookie2 = col.Get (cookie1.Name);
			cookie2.Value = "value2";

			cookie2 = col.Get (cookie1.Name);
			Assert.AreEqual ("value2", cookie2.Value, "col.Get doesn't copy");
		}
 public virtual NameValueCollection CreateStoreFromCookies(HttpCookieCollection cookies)
 {
     var cookieCount = cookies.Count;
     var store = new NameValueCollection(cookieCount);
     for (var i = 0; i < cookieCount; i++)
     {
         var cookie = cookies.Get(i);
         store.Add(cookie.Name, cookie.Value);
     }
     return store;
 }
        /// <summary>
        ///     Removes the authentication cookies.
        /// </summary>
        /// <param name="cookieCollection">The cookie collection.</param>
        private static void RemoveAuthCookies(HttpCookieCollection cookieCollection) {
            // borrar cualquier cookie con el mismo nombre de la cookie de autenticación
            if (!cookieCollection.AllKeys.Contains(FormsAuthentication.FormsCookieName)) return;
            //
            // obtener nombre definido paral a cookie
            var cookieName = FormsAuthentication.FormsCookieName;
            //
            // recuperar el valor de la cookie antes de eliminarla
            var httpCookie = cookieCollection.Get(cookieName);
            //
            // la cookie existe?
            if (httpCookie == null) return;
            //
            // eliminar la cookie
            cookieCollection.Remove(cookieName);
            //
            // determinar número de cookies en que se guardó el boleto de autenticación
            int numberOfCookies;

            if (!int.TryParse(httpCookie.Value, out numberOfCookies)) return;

            for (var i = 1; i < numberOfCookies; i++) cookieCollection.Remove((cookieName + i));
        }
Beispiel #21
0
		[Test] // Get (string)
		public void Get_Name ()
		{
			HttpCookieCollection col = new HttpCookieCollection ();
			Assert.IsNull (col.Get ("DOESNOTEXIST"), "#1");

			HttpCookie cookie1 = new HttpCookie ("cOokiE1", "value1");
			col.Add (cookie1);
			HttpCookie cookie2 = new HttpCookie ("cOokiE2", "value2");
			col.Add (cookie2);
			HttpCookie cookie3 = new HttpCookie ("cookie1", "value3");
			col.Add (cookie3);

			Assert.AreSame (cookie1, col.Get ("cOokiE1"), "#2");
			Assert.AreSame (cookie1, col.Get ("cookiE1"), "#3");
			Assert.AreSame (cookie2, col.Get ("cOokiE2"), "#4");
			Assert.AreSame (cookie2, col.Get ("COOkiE2"), "#5");
			Assert.IsNull (col.Get ((string) null), "#6");
			Assert.IsNull (col.Get ("DOESNOTEXIST"), "#7");
		}
Beispiel #22
0
        private void ValidateCookieCollection(HttpCookieCollection cc) {
            if (GranularValidationEnabled) {
                // Granular request validation is enabled - validate collection entries only as they're accessed.
                cc.EnableGranularValidation((key, value) => ValidateString(value, key, RequestValidationSource.Cookies));
            }
            else {
                // Granular request validation is disabled - eagerly validate all collection entries.
                int c = cc.Count;

                for (int i = 0; i < c; i++) {
                    String key = cc.GetKey(i);
                    String val = cc.Get(i).Value;

                    if (!String.IsNullOrEmpty(val))
                        ValidateString(val, key, RequestValidationSource.Cookies);
                }
            }
        }
Beispiel #23
0
 /// <summary>
 /// Converts The Cookies In The Given Cookie Collection in to HttpCookies
 /// </summary>
 /// <param name="cookies">The Cookie Collection To Be Converted</param>
 public static void ConvertCookiesToHttpOnly(HttpCookieCollection cookies)
 {
     for (int i=0;i<cookies.Count;i++)
     {
         ConvertCookieToHttpOnly(cookies.Get(i));
     }
 }