c# - CookieContainer bug? -
How do I confuse that the cookie controller handles the domain, so I make this test. This test shows. CookieContainer does not return any cookies for "example.com" but according to RFC it should return at least 2 cookies
Is not this a bug?
How to make it work
Here's a discussion about this bug:
;% @ Page language = "C #"% & gt; & Lt;% @ import namespace = "System.Net"% & gt; & Lt ;; DOCTYPE HTML PUBLIC "- // W3C // DTT XHTML 1.0 Transcription // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> & Lt; Script runat = "server" & gt; Cookie Container Let Container () {Cookie Contender Results = New Cookie Container (); Uri Uri = new Uri ("http://sub.example.com"); String cookieH = @ "test1 = well; domain = all.example.com; path = /"; result. Set cookies (Yuri, Cookie H); Cookie.h = @ "test2 = well; domain = .example.com; path = /"; result. Set cookies (Yuri, Cookie H); Cookie H = @ "test3 = well; domain = example com; path =" "; results; set cookies (yuri, cookie h); return result;} zero test () {cookie content cookie = (meet); LblResult.Text + = "& lt; Br> Total cookies count: "+ Cookie.Count +" & amp; Nbsp; And & nbsp; Expected: 3 "; Uri Uri = new Uri (" http://sub.example.com "); Cookie Collection coll = cookie.GetCookies (uri); LblResult.Text + =" & lt; Br> "+ uri +" cookie count: "+ coll.Count +" & amp; Nbsp; Expected: 2 "; Yuri = new Uri (" http://other.example.com "); Coll = cookie.GetCookies (uri); LblResult.Text + =" & lt; Br> "+ uri +" cookie count: "+ coll.Count +" & amp; Nbsp; Expected: 2 "; Yuri = New Uri (" http://example.com "); Coll = cookie.GetCookies (uri); LblResult.Text + =" & lt; Br> "+ uri +" cookie count: "+ coll.Count +" & amp; Nbsp; Expected: 2 ";} Secure Zero Page_load (Object Sender, EventAgds E) {Test ();} & lt; / script & gt; & lt; html xmlns =" http://www.w3.org/1999/xhtml "& Gt; head runat =" server ">
= "Text">CATEGORY CONTAINER TEST PAGE title> head> gt; & gt; body & gt; & Lt; form id = "frmTest" runat = "server" & gt; asp: Label ID = "lblResult" EnableViewState = "false" runat = "server" & gt; & lt; / asp: label & gt; ; & Lt; / form> body> I just got the solution for this bug and discussed here:
- Do not use .add (cookies), only use the .add (URI, cookie) method
Call: p> Here is the solution. you can add a cookie to the container or before you first use .GetCookie or use system container
private void BugFix_CookieDomain (CookieContainer cookieContainer) {System.Type _ContainerType = typeof (CookieContainer). Hashtable table = (Hashtable) _ContainerType.InvokeMember ( "m_domainTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, cookieContainer, new Object [] {}); ArrayList keys = new ArrayList (table.Keys); Foreign currency (string key obz in keys) {string key = (as key verb string); If (key [0] == '.') {String newKey = key.Remove (0, 1); Table [new k] = table [key oz]; }}
Comments
Post a Comment