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 ();
		}
Exemple #2
0
        /*
         *   Finalize the request
         */
        internal void EndRequest()
        {
            VerifyStart();

            if (_endDataCollected)
            {
                return;
            }

            // add some more information about the reponse
            DataRow row = _requestData.Tables[SR.Trace_Request].Rows[0];

            row[SR.Trace_Status_Code]       = _context.Response.StatusCode;
            row[SR.Trace_Response_Encoding] = _context.Response.ContentEncoding.EncodingName;

            IEnumerator en;
            string      temp;
            object      obj;
            int         i;


            // Application State info
            _context.Application.Lock();
            try {
                en = _context.Application.GetEnumerator();
                while (en.MoveNext())
                {
                    row  = NewRow(_requestData, SR.Trace_Application_State);
                    temp = (string)en.Current;

                    //the key might be null
                    row[SR.Trace_Application_Key] = (temp != null) ? temp : NULLSTRING;

                    obj = _context.Application[temp];

                    // the value could also be null
                    if (obj != null)
                    {
                        row[SR.Trace_Type]  = obj.GetType();
                        row[SR.Trace_Value] = obj.ToString();
                    }
                    else
                    {
                        row[SR.Trace_Type]  = NULLSTRING;
                        row[SR.Trace_Value] = NULLSTRING;
                    }

                    AddRow(_requestData, SR.Trace_Application_State, row);
                }
            }
            finally {
                _context.Application.UnLock();
            }

            // request cookie info
            HttpCookieCollection cookieCollection = new HttpCookieCollection();

            _context.Request.FillInCookiesCollection(cookieCollection, false /*includeResponse */);
            HttpCookie[] cookies = new HttpCookie[cookieCollection.Count];
            cookieCollection.CopyTo(cookies, 0);
            for (i = 0; i < cookies.Length; i++)
            {
                row = NewRow(_requestData, SR.Trace_Request_Cookies_Collection);
                row[SR.Trace_Name] = cookies[i].Name;
                if (cookies[i].Values.HasKeys())
                {
                    NameValueCollection subvalues = cookies[i].Values;
                    StringBuilder       sb        = new StringBuilder();

                    en = subvalues.GetEnumerator();
                    while (en.MoveNext())
                    {
                        temp = (string)en.Current;
                        sb.Append("(");
                        sb.Append(temp + "=");

                        sb.Append(cookies[i][temp] + ")  ");
                    }
                    row[SR.Trace_Value] = sb.ToString();
                }
                else
                {
                    row[SR.Trace_Value] = cookies[i].Value;
                }

                int size = (cookies[i].Name == null) ? 0 : cookies[i].Name.Length;
                size += (cookies[i].Value == null) ? 0 : cookies[i].Value.Length;

                row[SR.Trace_Size] = size + 1; // plus 1 for =
                AddRow(_requestData, SR.Trace_Request_Cookies_Collection, row);
            }

            // response cookie info
            cookies = new HttpCookie[_context.Response.Cookies.Count];
            _context.Response.Cookies.CopyTo(cookies, 0);
            for (i = 0; i < cookies.Length; i++)
            {
                row = NewRow(_requestData, SR.Trace_Response_Cookies_Collection);
                row[SR.Trace_Name] = cookies[i].Name;
                if (cookies[i].Values.HasKeys())
                {
                    NameValueCollection subvalues = cookies[i].Values;
                    StringBuilder       sb        = new StringBuilder();

                    en = subvalues.GetEnumerator();
                    while (en.MoveNext())
                    {
                        temp = (string)en.Current;
                        sb.Append("(");
                        sb.Append(temp + "=");

                        sb.Append(cookies[i][temp] + ")  ");
                    }
                    row[SR.Trace_Value] = sb.ToString();
                }
                else
                {
                    row[SR.Trace_Value] = cookies[i].Value;
                }

                int size = (cookies[i].Name == null) ? 0 : cookies[i].Name.Length;
                size += (cookies[i].Value == null) ? 0 : cookies[i].Value.Length;

                row[SR.Trace_Size] = size + 1; // plus 1 for =
                AddRow(_requestData, SR.Trace_Response_Cookies_Collection, row);
            }

            HttpSessionState session = _context.Session;

            // session state info
            if (session != null)
            {
                row = _requestData.Tables[SR.Trace_Request].Rows[0];
                try {
                    row[SR.Trace_Session_Id] = HttpUtility.UrlEncode(session.SessionID);
                }
                catch {
                    // VSWhidbey 527536
                    // Accessing SessionID can cause creation of the session id, this will throw in the
                    // cross page post scenario, as the response has already been flushed when we try
                    // to add the session cookie, since this is just trace output, we can just not set a session ID.
                    //
                }

                en = session.GetEnumerator();
                while (en.MoveNext())
                {
                    row = NewRow(_requestData, SR.Trace_Session_State);

                    temp = (string)en.Current;

                    // the key could be null
                    row[SR.Trace_Session_Key] = (temp != null) ? temp : NULLSTRING;

                    obj = session[temp];

                    // the value could also be null
                    if (obj != null)
                    {
                        row[SR.Trace_Type]  = obj.GetType();
                        row[SR.Trace_Value] = obj.ToString();
                    }
                    else
                    {
                        row[SR.Trace_Type]  = NULLSTRING;
                        row[SR.Trace_Value] = NULLSTRING;
                    }

                    AddRow(_requestData, SR.Trace_Session_State, row);
                }
            }

            ApplyTraceMode();
            OnTraceFinished(new TraceContextEventArgs(_traceRecords));
        }
        /*
         *   Finalize the request
         */
        internal void EndRequest() {
            VerifyStart();

            if (_endDataCollected)
                return;

            // add some more information about the reponse
            DataRow row = _requestData.Tables[SR.Trace_Request].Rows[0];
            row[SR.Trace_Status_Code] = _context.Response.StatusCode;
            row[SR.Trace_Response_Encoding] = _context.Response.ContentEncoding.EncodingName;

            IEnumerator en;
            string temp;
            object obj;
            int i;


            // Application State info
            _context.Application.Lock();
            try {
                en = _context.Application.GetEnumerator();
                while (en.MoveNext()) {
                    row = NewRow(_requestData, SR.Trace_Application_State);
                    temp = (string) en.Current;

                    //the key might be null
                    row[SR.Trace_Application_Key] = (temp != null) ? temp : NULLSTRING;

                    obj = _context.Application[temp];

                    // the value could also be null
                    if (obj != null) {
                        row[SR.Trace_Type] = obj.GetType();
                        row[SR.Trace_Value] = obj.ToString();
                    }
                    else {
                        row[SR.Trace_Type] = NULLSTRING;
                        row[SR.Trace_Value] = NULLSTRING;
                    }

                    AddRow(_requestData, SR.Trace_Application_State, row);
                }
            }
            finally {
                _context.Application.UnLock();
            }

            // request cookie info
            HttpCookieCollection cookieCollection = new HttpCookieCollection();
            _context.Request.FillInCookiesCollection(cookieCollection, false /*includeResponse */);
            HttpCookie[] cookies = new HttpCookie[cookieCollection.Count];
            cookieCollection.CopyTo(cookies, 0);
            for (i = 0; i<cookies.Length; i++) {
                row = NewRow(_requestData, SR.Trace_Request_Cookies_Collection);
                row[SR.Trace_Name] = cookies[i].Name;
                if (cookies[i].Values.HasKeys()) {
                    NameValueCollection subvalues = cookies[i].Values;
                    StringBuilder sb = new StringBuilder();

                    en = subvalues.GetEnumerator();
                    while (en.MoveNext()) {
                        temp = (string) en.Current;
                        sb.Append("(");
                        sb.Append(temp + "=");

                        sb.Append(cookies[i][temp] + ")  ");
                    }
                    row[SR.Trace_Value] = sb.ToString();
                }
                else
                    row[SR.Trace_Value] = cookies[i].Value;

                int size =  (cookies[i].Name  == null) ? 0 : cookies[i].Name.Length;
                size += (cookies[i].Value == null) ? 0 : cookies[i].Value.Length;

                row[SR.Trace_Size] = size + 1; // plus 1 for =
                AddRow(_requestData, SR.Trace_Request_Cookies_Collection, row);
            }

            // response cookie info
            cookies = new HttpCookie[_context.Response.Cookies.Count];
            _context.Response.Cookies.CopyTo(cookies, 0);
            for (i = 0; i<cookies.Length; i++) {
                row = NewRow(_requestData, SR.Trace_Response_Cookies_Collection);
                row[SR.Trace_Name] = cookies[i].Name;
                if (cookies[i].Values.HasKeys()) {
                    NameValueCollection subvalues = cookies[i].Values;
                    StringBuilder sb = new StringBuilder();

                    en = subvalues.GetEnumerator();
                    while (en.MoveNext()) {
                        temp = (string) en.Current;
                        sb.Append("(");
                        sb.Append(temp + "=");

                        sb.Append(cookies[i][temp] + ")  ");
                    }
                    row[SR.Trace_Value] = sb.ToString();
                }
                else
                    row[SR.Trace_Value] = cookies[i].Value;

                int size =  (cookies[i].Name  == null) ? 0 : cookies[i].Name.Length;
                size += (cookies[i].Value == null) ? 0 : cookies[i].Value.Length;

                row[SR.Trace_Size] = size + 1; // plus 1 for =
                AddRow(_requestData, SR.Trace_Response_Cookies_Collection, row);
            }

            HttpSessionState session = _context.Session;
            // session state info
            if (session != null) {
                row = _requestData.Tables[SR.Trace_Request].Rows[0];
                try {
                    row[SR.Trace_Session_Id] = HttpUtility.UrlEncode(session.SessionID);
                }
                catch {
                    // VSWhidbey 527536
                    // Accessing SessionID can cause creation of the session id, this will throw in the
                    // cross page post scenario, as the response has already been flushed when we try
                    // to add the session cookie, since this is just trace output, we can just not set a session ID.
                    // 
                }

                en = session.GetEnumerator();
                while (en.MoveNext()) {
                    row = NewRow(_requestData, SR.Trace_Session_State);

                    temp = (string) en.Current;

                    // the key could be null
                    row[SR.Trace_Session_Key] = (temp != null) ? temp : NULLSTRING;

                    obj = session[temp];

                    // the value could also be null
                    if (obj != null) {
                        row[SR.Trace_Type] = obj.GetType();
                        row[SR.Trace_Value] = obj.ToString();
                    }
                    else {
                        row[SR.Trace_Type] = NULLSTRING;
                        row[SR.Trace_Value] = NULLSTRING;
                    }

                    AddRow(_requestData, SR.Trace_Session_State, row);
                }
            }

            ApplyTraceMode();
            OnTraceFinished(new TraceContextEventArgs(_traceRecords));
        }
 internal void EndRequest()
 {
     this.VerifyStart();
     if (!this._endDataCollected)
     {
         IEnumerator enumerator;
         string      current;
         object      obj2;
         int         num;
         DataRow     row = this._requestData.Tables["Trace_Request"].Rows[0];
         row["Trace_Status_Code"]       = this._context.Response.StatusCode;
         row["Trace_Response_Encoding"] = this._context.Response.ContentEncoding.EncodingName;
         this._context.Application.Lock();
         try
         {
             enumerator = this._context.Application.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 row     = this.NewRow(this._requestData, "Trace_Application_State");
                 current = (string)enumerator.Current;
                 row["Trace_Application_Key"] = (current != null) ? current : "<null>";
                 obj2 = this._context.Application[current];
                 if (obj2 != null)
                 {
                     row["Trace_Type"]  = obj2.GetType();
                     row["Trace_Value"] = obj2.ToString();
                 }
                 else
                 {
                     row["Trace_Type"]  = "<null>";
                     row["Trace_Value"] = "<null>";
                 }
                 this.AddRow(this._requestData, "Trace_Application_State", row);
             }
         }
         finally
         {
             this._context.Application.UnLock();
         }
         HttpCookieCollection cookieCollection = new HttpCookieCollection();
         this._context.Request.FillInCookiesCollection(cookieCollection, false);
         HttpCookie[] dest = new HttpCookie[cookieCollection.Count];
         cookieCollection.CopyTo(dest, 0);
         for (num = 0; num < dest.Length; num++)
         {
             row = this.NewRow(this._requestData, "Trace_Request_Cookies_Collection");
             row["Trace_Name"] = dest[num].Name;
             if (dest[num].Values.HasKeys())
             {
                 NameValueCollection values  = dest[num].Values;
                 StringBuilder       builder = new StringBuilder();
                 enumerator = values.GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     current = (string)enumerator.Current;
                     builder.Append("(");
                     builder.Append(current + "=");
                     builder.Append(dest[num][current] + ")  ");
                 }
                 row["Trace_Value"] = builder.ToString();
             }
             else
             {
                 row["Trace_Value"] = dest[num].Value;
             }
             int num2 = (dest[num].Name == null) ? 0 : dest[num].Name.Length;
             num2 += (dest[num].Value == null) ? 0 : dest[num].Value.Length;
             row["Trace_Size"] = num2 + 1;
             this.AddRow(this._requestData, "Trace_Request_Cookies_Collection", row);
         }
         dest = new HttpCookie[this._context.Response.Cookies.Count];
         this._context.Response.Cookies.CopyTo(dest, 0);
         for (num = 0; num < dest.Length; num++)
         {
             row = this.NewRow(this._requestData, "Trace_Response_Cookies_Collection");
             row["Trace_Name"] = dest[num].Name;
             if (dest[num].Values.HasKeys())
             {
                 NameValueCollection values2  = dest[num].Values;
                 StringBuilder       builder2 = new StringBuilder();
                 enumerator = values2.GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     current = (string)enumerator.Current;
                     builder2.Append("(");
                     builder2.Append(current + "=");
                     builder2.Append(dest[num][current] + ")  ");
                 }
                 row["Trace_Value"] = builder2.ToString();
             }
             else
             {
                 row["Trace_Value"] = dest[num].Value;
             }
             int num3 = (dest[num].Name == null) ? 0 : dest[num].Name.Length;
             num3 += (dest[num].Value == null) ? 0 : dest[num].Value.Length;
             row["Trace_Size"] = num3 + 1;
             this.AddRow(this._requestData, "Trace_Response_Cookies_Collection", row);
         }
         HttpSessionState session = this._context.Session;
         if (session != null)
         {
             row = this._requestData.Tables["Trace_Request"].Rows[0];
             try
             {
                 row["Trace_Session_Id"] = HttpUtility.UrlEncode(session.SessionID);
             }
             catch
             {
             }
             enumerator = session.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 row     = this.NewRow(this._requestData, "Trace_Session_State");
                 current = (string)enumerator.Current;
                 row["Trace_Session_Key"] = (current != null) ? current : "<null>";
                 obj2 = session[current];
                 if (obj2 != null)
                 {
                     row["Trace_Type"]  = obj2.GetType();
                     row["Trace_Value"] = obj2.ToString();
                 }
                 else
                 {
                     row["Trace_Type"]  = "<null>";
                     row["Trace_Value"] = "<null>";
                 }
                 this.AddRow(this._requestData, "Trace_Session_State", row);
             }
         }
         this.ApplyTraceMode();
         this.OnTraceFinished(new TraceContextEventArgs(this._traceRecords));
     }
 }
 internal void EndRequest()
 {
     this.VerifyStart();
     if (!this._endDataCollected)
     {
         IEnumerator enumerator;
         string current;
         object obj2;
         int num;
         DataRow row = this._requestData.Tables["Trace_Request"].Rows[0];
         row["Trace_Status_Code"] = this._context.Response.StatusCode;
         row["Trace_Response_Encoding"] = this._context.Response.ContentEncoding.EncodingName;
         this._context.Application.Lock();
         try
         {
             enumerator = this._context.Application.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 row = this.NewRow(this._requestData, "Trace_Application_State");
                 current = (string) enumerator.Current;
                 row["Trace_Application_Key"] = (current != null) ? current : "<null>";
                 obj2 = this._context.Application[current];
                 if (obj2 != null)
                 {
                     row["Trace_Type"] = obj2.GetType();
                     row["Trace_Value"] = obj2.ToString();
                 }
                 else
                 {
                     row["Trace_Type"] = "<null>";
                     row["Trace_Value"] = "<null>";
                 }
                 this.AddRow(this._requestData, "Trace_Application_State", row);
             }
         }
         finally
         {
             this._context.Application.UnLock();
         }
         HttpCookieCollection cookieCollection = new HttpCookieCollection();
         this._context.Request.FillInCookiesCollection(cookieCollection, false);
         HttpCookie[] dest = new HttpCookie[cookieCollection.Count];
         cookieCollection.CopyTo(dest, 0);
         for (num = 0; num < dest.Length; num++)
         {
             row = this.NewRow(this._requestData, "Trace_Request_Cookies_Collection");
             row["Trace_Name"] = dest[num].Name;
             if (dest[num].Values.HasKeys())
             {
                 NameValueCollection values = dest[num].Values;
                 StringBuilder builder = new StringBuilder();
                 enumerator = values.GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     current = (string) enumerator.Current;
                     builder.Append("(");
                     builder.Append(current + "=");
                     builder.Append(dest[num][current] + ")  ");
                 }
                 row["Trace_Value"] = builder.ToString();
             }
             else
             {
                 row["Trace_Value"] = dest[num].Value;
             }
             int num2 = (dest[num].Name == null) ? 0 : dest[num].Name.Length;
             num2 += (dest[num].Value == null) ? 0 : dest[num].Value.Length;
             row["Trace_Size"] = num2 + 1;
             this.AddRow(this._requestData, "Trace_Request_Cookies_Collection", row);
         }
         dest = new HttpCookie[this._context.Response.Cookies.Count];
         this._context.Response.Cookies.CopyTo(dest, 0);
         for (num = 0; num < dest.Length; num++)
         {
             row = this.NewRow(this._requestData, "Trace_Response_Cookies_Collection");
             row["Trace_Name"] = dest[num].Name;
             if (dest[num].Values.HasKeys())
             {
                 NameValueCollection values2 = dest[num].Values;
                 StringBuilder builder2 = new StringBuilder();
                 enumerator = values2.GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     current = (string) enumerator.Current;
                     builder2.Append("(");
                     builder2.Append(current + "=");
                     builder2.Append(dest[num][current] + ")  ");
                 }
                 row["Trace_Value"] = builder2.ToString();
             }
             else
             {
                 row["Trace_Value"] = dest[num].Value;
             }
             int num3 = (dest[num].Name == null) ? 0 : dest[num].Name.Length;
             num3 += (dest[num].Value == null) ? 0 : dest[num].Value.Length;
             row["Trace_Size"] = num3 + 1;
             this.AddRow(this._requestData, "Trace_Response_Cookies_Collection", row);
         }
         HttpSessionState session = this._context.Session;
         if (session != null)
         {
             row = this._requestData.Tables["Trace_Request"].Rows[0];
             try
             {
                 row["Trace_Session_Id"] = HttpUtility.UrlEncode(session.SessionID);
             }
             catch
             {
             }
             enumerator = session.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 row = this.NewRow(this._requestData, "Trace_Session_State");
                 current = (string) enumerator.Current;
                 row["Trace_Session_Key"] = (current != null) ? current : "<null>";
                 obj2 = session[current];
                 if (obj2 != null)
                 {
                     row["Trace_Type"] = obj2.GetType();
                     row["Trace_Value"] = obj2.ToString();
                 }
                 else
                 {
                     row["Trace_Type"] = "<null>";
                     row["Trace_Value"] = "<null>";
                 }
                 this.AddRow(this._requestData, "Trace_Session_State", row);
             }
         }
         this.ApplyTraceMode();
         this.OnTraceFinished(new TraceContextEventArgs(this._traceRecords));
     }
 }
		public void CopyToTest ()
		{
			HttpCookieCollection col = new HttpCookieCollection ();
			HttpCookie[] cookies = new HttpCookie[2];

			col.Add (new HttpCookie ("cookie1", "value1"));
			col.Add (new HttpCookie ("cookie2", "value2"));

			col.CopyTo (cookies, 0);

			Assert.AreEqual ("cookie1", cookies[0].Name, "cookies[0].Name");
			Assert.AreEqual ("cookie2", cookies[1].Name, "cookies[1].Name");
		}