Using Cookies


Giulio Petrucci

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 = ...;


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)

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

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,


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question