Application not getting full list of cookies, only a few. RRS feed

  • Question

  • Hi, i'm creating a application that gets all cookies from a website but for some reason my application only outputs a few. Why is this happening and is this fixable?

    string url = textBox1.Text;
    HttpWebRequest myCall = (HttpWebRequest)WebRequest.Create(url); 
    myCall.CookieContainer = new CookieContainer();
    response = (HttpWebResponse)myCall.GetResponse();
    myCall.AllowAutoRedirect = true;
    foreach (Cookie cookie in response.Cookies)
    catch(Exception ex)

    Tuesday, October 17, 2017 4:10 PM


  • Hello CodingDoggo,

    The Cookie is attached to the response, so if you do something like RedirectToAction will stop from sending the cookie to the user,in other words,you will lost the cookies in your current request ,Please check your server-side code.

    And if you just want to save cookie for testing without web page content. you could Set the AllowAutoRedirect=false before getting response.

    HttpWebRequest myCall = (HttpWebRequest)WebRequest.Create("xxxx/home/index");
    myCall.CookieContainer = new CookieContainer();
    myCall.AllowAutoRedirect = false;
    HttpWebResponse response = (HttpWebResponse)myCall.GetResponse();

    There is a article about handling cookies and redirect operations.

    Note . If you set the AllowAutoRedirect as false ,you will not get the redirect page content.


    Neil Hu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    • Edited by Fei HuModerator Wednesday, October 18, 2017 9:14 AM
    • Marked as answer by CodingDoggo Thursday, October 19, 2017 12:49 PM
    Wednesday, October 18, 2017 7:29 AM