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

Randomly request timeout (IIS6.0)

Hi!
I have got IIS 6.0 on Windows 2003 Server. I have installed HTTP
handler (as simple reverse-proxy) - code below. I created virtual
category with this dll and Wilcard application mapping set to
aspnet_isapi.dll

Now everything works fine, but sometimes IIS stops working and return
'Error in /catalog Application. Request timeout...' And than i must
restart IIS (at least application pools).

Thanks for help,
Filip

Code of Handler.cs:

/*
Handler.cs; v 1.1; 2005/10/25; Filip Balicki
Script capture all references to selected in Web.config virtual
directory, and download resources from
selected (also in Web.config) remote host. (so it is work as
proxy)
*/

using System;
using System.Web;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections;
using System.Configuration;

namespace Polygon
{

public class Handler : IHttpHandler
{
string host_address
{
get
//Take local address (where this script
is installed) from
web.config
//http://my_domain/virtual_catalog/
{
return
ParseUrl(ConfigurationSettings.AppSettings["local_address"]);
}
}
string dest_adress
{
get
//Take local address (where this script
is installed) from
web.config
//http://my_domain/virtual_catalog/
{
return
ParseUrl(ConfigurationSettings.AppSettings["destination_host"]);
}
}
public void ProcessRequest(HttpContext context)
{

string my_uri = context.Request.Url.ToString();
//construct real uri to remote host
string real_uri = Regex.Replace (my_uri,
host_address,dest_adress,RegexOptions.Multiline |
RegexOptions.IgnoreCase);
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(real_uri);
request.KeepAlive = false;
request.AllowAutoRedirect = false;
HttpWebResponse response;
try
{
response = (HttpWebResponse)
request.GetResponse();
}
catch(System.Net.WebException we)
{
context.Response.StatusCode = 404;
context.Response.StatusDescription =
"Not Found ("+we.Message+")";
response = (HttpWebResponse)
we.Response;
writeBody(context, response);
return;
}
if (response.StatusCode != HttpStatusCode.OK)
//Found not OK header - probably
redirect
{
context.Response.AddHeader("Location",
response.Headers["Location"]);

context.Response.AddHeader("Content-Type", response.ContentType);
context.Response.StatusCode = (int)
response.StatusCode;
}
else
{

context.Response.AddHeader("Content-Type", response.ContentType);
writeBody (context, response);
}
response.Close();
context.Response.End();

}

public bool IsReusable
{
get
{
return true;
}
}

public string ParseUrl (string url)
{
if ((char)url[url.Length-1]!= '/')
{
url+='/';
}
return url;
}

public void writeBody (HttpContext context,
HttpWebResponse response)
{
Stream receiveStream =
response.GetResponseStream();
if
((response.ContentType.ToLower().IndexOf("html")>= 0)

||(response.ContentType.ToLower().IndexOf("javascr ipt")>=0))
//if we get html or javascript use ASCI
mode
{
string body;
StreamReader readStream = new
StreamReader (receiveStream,
Encoding.Default);
body = readStream.ReadToEnd();
context.Response.Write(body);
}
else
{
//the response is not HTML - use binary
mode
byte[] buff = new byte[1024];
int bytes = 0;
while( ( bytes = receiveStream.Read(
buff, 0, 1024 ) ) > 0 )
{
//Write the stream directly to
the client

context.Response.OutputStream.Write (buff, 0, bytes );
}
}
response.Close();
}

}

Jun 28 '06 #1
0 1266

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

Similar topics

1
by: Phil S | last post by:
My server is randomly restarting every few minutes or so, and I can't figure out why. What would cause this to happen, aside from some evil person sitting at the console? I did manage to catch it...
2
by: James M. | last post by:
I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup with NLB (single Affinity, also using SQLServer session state) that are hosting a few .NET ASP web applications under the Default Website...
11
by: Ed Dearlove | last post by:
**Also posted in inetserver.iis newsgroup as I am unsure of where the problem lies** Hi, I have a strange problem, or I may just be stupid, but wondering if anyone can help with this one: ...
5
by: fbwhite | last post by:
I know this issue has been brought up many times, but I have tried many of the solutions to no avail. I wanted to give my specific case to see if someone could be of any help. We are using the...
0
by: James M via .NET 247 | last post by:
(I have 2x Front-end Web servers (Win2003 Ent IIS6.0), setup withNLB (single Affinity, also using SQLServer session state) thatare hosting a few .NET ASP web applications under the DefaultWebsite in...
10
by: Jeff Shepler | last post by:
This is probably not the right newsgroup for this, but this is the only one I read and there are a lot of smart people that "live" here. Please don't berate me if you think this should have been...
2
by: AnalogKid17 | last post by:
Keywords: ASP.NET app with VS2005 running on Win2003 with IIS6, and SQL2000 on a WinXP Box I've betting the following for days... it's driving me insane: Server Error in '/' Application. ...
5
by: chromis | last post by:
Hi there, I've recently been updating a site to use locking on application level variables, and I am trying to use a commonly used method which copies the application struct into the request...
3
by: dihola | last post by:
Hi, I have a website running in IIS7 and it seems to be creating a new session for every request I make. The values I store in Session are lost with every request. This is the forms bit in my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.