OK, then explain this:
CookieTest1.ashx:
1 <% @ WebHandler language="C#" class="TestCookieHandler1" %>
2
3 using System;
4 using System.Web;
5
6 public class TestCookieHandler1 : IHttpHandler
7 {
8 public bool IsReusable
9 {
10 get { return false; }
11 }
12
13 public void ProcessRequest(HttpContext context)
14 {
15 HttpCookie cookie = new HttpCookie("TestCookie", "CookieTest1.ashx");
16 context.Response.Cookies.Set(cookie);
17 context.Response.Redirect("CookieTest2.ashx");
18 }
19 }
CookieTest2.ashx:
1 <% @ WebHandler language="C#" class="TestCookieHandler2" %>
2
3 using System;
4 using System.Web;
5
6 public class TestCookieHandler2 : IHttpHandler
7 {
8 public bool IsReusable
9 {
10 get { return false; }
11 }
12
13 public void ProcessRequest(HttpContext context)
14 {
15 HttpCookie cookie = new HttpCookie("testcookie", "CookieTest2.ashx");
16 context.Response.Cookies.Set(cookie);
17 context.Response.Redirect("CookieTest3.ashx");
18 }
19 }
CookieTest3.ashx:
1 <% @ WebHandler language="C#" class="TestCookieHandler3" %>
2
3 using System;
4 using System.IO;
5 using System.Web;
6
7 public class TestCookieHandler3 : IHttpHandler
8 {
9 public bool IsReusable
10 {
11 get { return false; }
12 }
13
14 public void ProcessRequest(HttpContext context)
15 {
16 RenderCookies(context.Response.Output, context.Request.Cookies);
17 }
18
19 private void RenderCookies(TextWriter writer, HttpCookieCollection cookies)
20 {
21 writer.Write("<html><head><title>Cookie Test</title></head><body><ul>");
22
23 writer.Write("<li><b>Keys:</b> ["");
24 HttpUtility.HtmlEncode(string.Join("\", \"", cookies.AllKeys), writer);
25 writer.Write(""]</li>");
26
27 for (int index = 0; index < cookies.Count; index++)
28 {
29 writer.Write("<li>{0:D}> <b>", index);
30 HttpUtility.HtmlEncode(cookies.GetKey(index), writer);
31 writer.Write("</b> = "");
32 HttpUtility.HtmlEncode(cookies[index].Value, writer);
33 writer.Write(""</li>");
34 }
35
36 writer.Write("<li><b>TestCookie</b> = "");
37 HttpUtility.HtmlEncode(cookies["TestCookie"].Value, writer);
38 writer.Write(""</li>");
39
40 writer.Write("<li><b>testcookie</b> = "");
41 HttpUtility.HtmlEncode(cookies["testcookie"].Value, writer);
42 writer.Write(""</li>");
43
44 writer.Write("</ul></body></html>");
45 }
46 }
Save these three files in a folder on your web-server, and navigate to CookieTest1.ashx. If cookie names are NOT case-sensitive, there should only be one instance of the "TestCookie" cookie, and it should have a value of "CookieTest2.ashx".
In IE7, Firefox 2 and Opera 9, the final output reads:
- Keys: ["TestCookie", "testcookie"]
- 0> TestCookie = "CookieTest1.ashx"
- 1> testcookie = "CookieTest2.ashx"
- TestCookie = "CookieTest1.ashx"
- testcookie = "CookieTest1.ashx"