本文整理汇总了C#中System.Web.HttpCookieCollection.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# HttpCookieCollection.CopyTo方法的具体用法?C# HttpCookieCollection.CopyTo怎么用?C# HttpCookieCollection.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpCookieCollection
的用法示例。
在下文中一共展示了HttpCookieCollection.CopyTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deny_Unrestricted
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 ();
}
示例2: EndRequest
/*
* 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] + ") ");
}
//.........这里部分代码省略.........
示例3: EndRequest
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;
//.........这里部分代码省略.........
示例4: CopyToTest
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");
}