Re: changing Request.InputStream

From: Karahan Celikel (NOkarahan_celikelSPAM_at_hotmail.com)
Date: 03/04/04


Date: Thu, 4 Mar 2004 11:24:46 -0600

Hi Steven,

Actually Request.InputStream is readonly. As far as I understand it is the
Filter that can be writable. If there is a filter of the request then
Application uses this filter instead of Request.InputStream.
Yesterday , I found a workaround to the problem. But it is not an elegant
solution.

Before the following Read method of the filter is called

public override int Read(byte[] buffer, int offset, int count)
{
int c = _sink.Read(buffer, offset, count);
Here I want to change the buffer
return c;
}

size of the buffer array and count parameters are determined by the the
Length property of the Filter itself. So we can deceive the caller here by
manipulating the Length property. Here we can generate the new request
string and return the length of it

public override long Length
{
    get
    {
        if(this.newRequestStr!="")
            return this.newRequestStr.Length;
        else
        {
            if(_sink.Length!=0)
            {
                this.newRequestStr = ProcessRequest();
                return this.newRequestStr.Length;
            }
            else
                return 0;
        }
    }
}

and we need to change the Read method

 public override int Read(byte[] buffer, int offset, int count)
  {
   byte[] newBuffer =
System.Text.Encoding.UTF8.GetBytes(this.newRequestStr);

   for(int i=0;i<count;i++)
    buffer[i] = newBuffer[i];

   return newRequestStr.Length;
  }

But as you can see, generating the new request string in the getter of the
Length property is something like a hack rather than an elegant solution.

I would appreciate if you can investigate it further. There is not much
documentation about this topic.

Thanks

Karahan Celikel



Relevant Pages

  • Re: Tricky Request Filtering Issue
    ... filter has been wired up results in a double firing of the filter's Read ... Request and Response filters at the start of each transaction. ... public override int Read ... stream in, and write it out modified anyway your want. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to buffer output samples from AVIMux ?
    ... >> and then sent them all down to the AVIWriter filter as a bulk! ... sound but writing it out just on request ... AVIWriter just when necessary.Also, another issue is that once the ... So I have to buffer all these "past" samples in a way ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: IIS Extensions in URL causes filter to break.
    ... If your filter operates the way you say, ... IIS can only say that one or more of the events contain ... every request, and maybe more than once, depending on whether the URL causes ... As for the order of handling between ISAPI Extensions and Filters - Filters ...
    (microsoft.public.inetserver.iis.security)
  • RE: iis crash/hang agent
    ... ;;; which is represented by a request that takes too long to complete. ... In the case of a hang, the agent can write a log file ... Configure the IISCHAgent.dll as a global filter in IIS by running ... Specifies the maximum number of CrashAgent logs to keep. ...
    (microsoft.public.inetserver.iis)
  • Re: Bybass HTTP ( extension files ) in ISA 2004
    ... The request was rejected by the HTTP filter. ... Contact your ISA Server administrator. ...
    (Bugtraq)