Randomly request timeout (IIS6.0)

Discussion in 'ASP .Net' started by felippe, Jun 28, 2006.

  1. felippe

    felippe Guest

    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("javascript")>=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();
    }

    }
    felippe, Jun 28, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Captain Chaos

    Request is done twice randomly

    Captain Chaos, Dec 29, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    324
    Captain Chaos
    Dec 30, 2003
  2. scott

    asp session timeout on IIS6

    scott, Sep 7, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,240
    scott
    Sep 8, 2004
  3. Lars-Erik Aabech
    Replies:
    3
    Views:
    386
    [MSFT]
    Apr 29, 2005
  4. P. Glassel

    Classic ASP session timeout under IIS6.0

    P. Glassel, Jul 26, 2003, in forum: ASP General
    Replies:
    5
    Views:
    792
    Michael D. Kersey
    Jul 28, 2003
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,250
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page