Using Cookies

Discussion in 'ASP .Net' started by Giulio Petrucci, Nov 18, 2009.

  1. Hi there,

    I need to test an ASP.NET web site with multiple http sessions, using a
    command line C# application. My idea is to run (at least) two threads to
    emulate the different sessions, with each threat polling the web site to
    emulate different requests within the same session. In the test phase we
    can assume the following code:

    public partial class TestPage : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    System.Diagnostic.DefaultTraceListener dtl = ...;

    dtl.WriteLine(HttpContext.Current.Session.GetHashCode().ToString());
    }
    }

    The problem is that I cannot handle the sessions client side. Googling
    around I found something about cookies, so I wrote this snippet down:

    string requestUrl = "...";
    int requestNo = 10;

    CookieContainer cc = null;
    for (int i = 0; i < requestNo; i++)
    {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
    request.CookieContainer = cc;
    HttpWebResponse response = (HttpWebResponse)
    request.GetResponse();

    cc = new CookieContainer();
    foreach (Cookie c in response.Cookies)
    cc.Add(c);
    }

    but at the first step 'response.Cookies' is empty.
    Am I missing anything on the server-side? Am I missing anything *at
    all*? ;-)

    Thanks in advance,
    Giulio
    --
    Giulio Petrucci, Nov 18, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,456
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,504
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    648
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    499
  5. _Who
    Replies:
    7
    Views:
    2,633
Loading...

Share This Page