HttpWebRequest Session/Timeout Problem

C

Craig

I wrote a generic page to do HttpWebRequest operations based on 3
querystring parameters for the uri, username, and password for basic
authentication pages. The page is designed to help with network
management... You would use the page like this:

http://localhost/webform1.aspx?uri=http://pagetomonitor.com&user=someuser&pass=somepass

Anyway, what seems to happen is that the first 2 or 3 calls to the page with
a given set of parameters works great, but then every request after that
times out until you restart the web app. If I try to call a different page
with the uri parameter, it works fine the first 2 or 3 times, then does that
same thing. It's like the web server only allows you to create 2 or 3
sessions and then denies you any more. Is this what's happening? Is there
a way to send a 'Close my Session' command to the web server after I get the
response?

My code is below:
string user;

string pass;

string uri;

private void Page_Load(object sender, System.EventArgs e)

{

if (Request.QueryString["user"]==null || Request.QueryString["pass"]==null
|| Request.QueryString["uri"]==null)

{

Response.Write("Please provide valid user, pass, and uri parameters in the
URL");

Response.End();

}

user = Request.QueryString["user"];

pass = Request.QueryString["pass"];

uri = Request.QueryString["uri"];

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);

webRequest.Credentials = new System.Net.NetworkCredential(user,pass);

webRequest.Timeout = 10000;

webRequest.AllowAutoRedirect = true;

try

{

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

WebHeaderCollection headers = new WebHeaderCollection();

Response.Write("<B>Headers</B><BR>");

for (int x = 0;x<webResponse.Headers.Count;x++)

{

Response.Write(webResponse.Headers.Keys[x] +": "+
webResponse.Headers[x]+"<BR>");

}

Response.Write("<BR><B>Stauts</B><BR>");

Response.Write("StatusCode: " + webResponse.StatusCode+"<BR>");

Response.Write("StatusDescription: " +
webResponse.StatusDescription+"<BR>");

}

catch (Exception ex)

{

Response.Write("Error Getting Page: " +ex.Message);

}

}
 

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

Top