473,320 Members | 1,746 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,320 software developers and data experts.

HttpWebRequest Operation Has Timed Out After Numerous Requests #2

Hey Group,

I'm in the process of converting an ASP-based site to an ASP.NET site and
built a control that wraps around an ASP page. The control simply does a GET
to the same server to render the ASP content, and then just writes it to the
page.

In development and testing, there were no problems. Once deployed to
production, after the site runs for a few hours, it starts to slow down and
throw countless "Operation Has Timed Out" WebExceptions.

I'm not exactly sure what's wrong with my code. In the global.asax, I have
the ServicePointManager.DefaultConnectionLimit set to 1000. All this seems to
do is extend how long it takes for timeouts to occur.

Any idea what I'm doing wrong?

Thanks,
Alex

(PS -- Hoping a repost will maket his message seen again)

---- CODE ----
public class AspPage : WebControl
{
public AspPage() {}

private StringBuilder _text = new StringBuilder();

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
RequestPage();
}

private void RequestPage()
{
//create a wrapper around the _text field
StringWriter writer = new StringWriter(_text);

//build the request
HttpWebRequest rqst = BuildRequest();

//get the response
HttpWebResponse resp = null;
try
{
//make the request
try
{
resp = (HttpWebResponse)rqst.GetResponse();
}
catch (WebException ex)
{
resp = (HttpWebResponse)ex.Response;
if (resp == null)
{
writer.Write(ex.ToString());
return;
}
}

//perhaps there was an error, a timeout
if (resp == null)
{
writer.Write("An unknown error occured.");
return;
}
//Pass Cookies back out
foreach (Cookie cook in resp.Cookies)
{
HttpCookie cookie = new HttpCookie(cook.Name, cook.Value);
cookie.Expires = cook.Expires;
Page.Response.Cookies.Add(cookie);
}

//Set Roles/Username from headers
if (GetMagHeaders)
{
HttpContext.Current.Session["MAGROLES"] = string.Format("{0}",
resp.Headers["MAGROLES"]);
HttpContext.Current.Session["MAGUSERNAME"] = string.Format("{0}",
resp.Headers["MAGUSERNAME"]);
}
//Redirect if appropriate
if ((resp.StatusCode == HttpStatusCode.Found) ||
(resp.StatusCode == HttpStatusCode.Redirect) ||
(resp.StatusCode == HttpStatusCode.Moved) ||
(resp.StatusCode == HttpStatusCode.MovedPermanently))
{
Page.Response.Redirect(resp.Headers["Location"]);
}

//write out the response
StreamReader reader = null;
try
{
reader = new StreamReader(resp.GetResponseStream());
writer.Write(reader.ReadToEnd());
}
finally
{
if (reader !=null) reader.Close();
}

}
finally
{
if (resp != null) resp.Close();
}
}

private HttpWebRequest BuildRequest()
{
//build the Uri to request
UriBuilder uri = new UriBuilder(Page.Request.Url);
uri.Path = Page.ResolveUrl(Url);

//URI Querystring
if (CopyQueryString) uri.Query = Page.Request.QueryString.ToString();
else if (QueryString != String.Empty) uri.Query = QueryString;

//Request to return
HttpWebRequest rqst = (HttpWebRequest)WebRequest.Create(uri.Uri);
rqst.AllowAutoRedirect = false;
rqst.KeepAlive = false;

//special header
rqst.Headers.Add("DOTNET-REQUEST", "yes");

//Misc Headers
rqst.Headers["HTTP_REFERER"] = Page.Request.Headers["HTTP_REFERER"];
rqst.UserAgent = Page.Request.UserAgent;

//copy cookies
if (Page.Request.Cookies.Count > 0)
{
rqst.CookieContainer = new CookieContainer(Page.Request.Cookies.Count);
foreach (string name in Page.Request.Cookies)
{
Cookie cookie = new Cookie(name, Page.Request.Cookies[name].Value);
rqst.CookieContainer.Add(rqst.RequestUri, cookie);
}
}
else
{
rqst.CookieContainer = new CookieContainer();
}

//body
if (CopyForm && Page.Request.RequestType.ToUpper() == "POST")
{
rqst.Method = "POST";
rqst.ContentType = Page.Request.ContentType;
rqst.ContentLength = Page.Request.ContentLength;

Stream input = Page.Request.InputStream;
Stream output = rqst.GetRequestStream();

byte[] buffer = new byte[2048];
int bytesRead = input.Read(buffer, 0, 2048);
while (bytesRead != 0)
{
output.Write(buffer, 0, bytesRead);
bytesRead = input.Read(buffer, 0, 2048);
}

output.Close();
}
return rqst;
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write(_text.ToString());
}

/* Snip Properties */
}

Jan 30 '06 #1
0 2018

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
9
by: Mike Cronin via DotNetMonster.com | last post by:
Hi there, Can anyone tell me what level of encryption is used when making an HTTPS POST request through an instance of the System.Net.HttpWebRequest object? Thanks much in advance! Mike...
4
by: Mark Fletcher | last post by:
Hi, Im in the process of writing a program that crawls a website. Im using the HttpWebRequest and HttpWebResponse classed to get content. To make my application more scalable, my application is...
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...
1
by: | last post by:
I have a strange behavior of a following code: HttpWebRequest request=(HttpWebRequest)WebRequest.Create(@"http://.../target.jsp"); request.ProtocolVersion=HttpVersion.Version11;...
1
by: Manso | last post by:
Hi, I have an ASP.NET 1.1 app running on Windows XP SP2 that is requesting information from a WebService which works just fine. Another part of the app is doing a server-side post to antoher...
0
by: Alex Papadimoulis | last post by:
Hey Group, I'm in the process of converting an ASP-based site to an ASP.NET site and built a control that wraps around an ASP page. The control simply does a GET to the same server to render the...
1
by: mroffey | last post by:
Hi I'm using the code below to post to a web form, but when I run it, i get System.Net.WebException: The operation has timed-out. error Obviously something is wrong, can anyone give me a clue?...
1
by: Eric Cadwell | last post by:
Are there two distinct timeouts on HttpWebRequest.GetResponse()? If I recall correctly, I've seen an "operation timed out" that was not the same as request time out. Thanks, Eric
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.