469,883 Members | 1,158 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,883 developers. It's quick & easy.

HttpWebRequest Session/Timeout Problem

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=h...&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);

}

}
Nov 15 '05 #1
1 13438
Nevermind, all that was needed was this:

webResponse.Close();
"Craig" <so*****@microsoft.com> wrote in message
news:0a*********************@twister.rdc-kc.rr.com...
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=h...&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);

}

}

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jerry Rhodes | last post: by
1 post views Thread by Jeff B | last post: by
2 posts views Thread by Keith Patrick | last post: by
11 posts views Thread by Keith Patrick | last post: by
reply views Thread by Susan Van Houen | last post: by
reply views Thread by Morgan Cheng | last post: by
1 post views Thread by ALA | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.