473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 14210
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jerry Rhodes | last post by:
When I run the code below, the web server tells me that I need to enable cookies. Can anyone tell me what might be causing that? I'm trying to POST userid and password to their login web page. ...
1
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some...
2
by: Keith Patrick | last post by:
I'm trying to programmatically post data to another page within my ASP.Net app. Not POSTing is not an option (I can't store this data in my session, context, hidden fields, or anything else...I've...
11
by: Keith Patrick | last post by:
Could someone explain to me the relationship between these two classes? I am ripping my hair out trying to divert an HttpRequest to a new location via an HttpWebRequest, but I cannot get my...
3
by: Amil | last post by:
Please don't repond to this if you are guessing or just don't know the answer. I'm trying to login to a backend system running Java/Tomcat. I create a HttpWebRequest with the login data and do...
1
by: davvel | last post by:
It has been 6 days of re-writing the same code in different ways to try and avoid a getResponse Timeout which haunted me for much too long now. I am trying to do a very simple thing which is...
0
by: Susan Van Houen | last post by:
Hi Everybody, I have a problem that is driving me crazy and I am hoping for some help here. I am building an application (vb.net, vs2003) that crawls selected websites. The application works...
0
by: Morgan Cheng | last post by:
In the doc http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.timeout.aspx, it reads, "A Domain Name System (DNS) query may take up to 15 seconds to return or time out. If your...
1
by: ALA | last post by:
Hi, does anybody know if it is possible to pass the SessionID with a web request by using a cookie so that the invoked page in the same domain can access the session objects of the current user?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.