<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>HttpHandlers and HttpModules</title><link>http://forums.asp.net/27.aspx</link><description>Extending the ASP.NET Framework through HttpModules and HttpHandlers.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Request.Filter</title><link>http://forums.asp.net/thread/3285492.aspx</link><pubDate>Fri, 10 Jul 2009 08:10:31 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3285492</guid><dc:creator>mulisak</dc:creator><author>mulisak</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3285492.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=27&amp;PostID=3285492</wfw:commentRss><description>&lt;p&gt;I have got it working, see example here:&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:;FONT-SIZE:x-small;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httprequest.filter.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.web.httprequest.filter.aspx&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If you need to do filtering in http module, use the code below.&lt;/p&gt;
&lt;p&gt;My problem was that before attaching the filter I checked for HttpContext.Current.Request.InputStream.Length &amp;gt; 0&amp;nbsp;which must have had a side effect of reading the input stream and bypassing filtering.&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:;FONT-SIZE:x-small;"&gt;&lt;font size="2"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;   public class FilterHttpModule : System.Web.IHttpModule
    {
        void IHttpModule.Dispose()
        {
        }

        void IHttpModule.Init(HttpApplication context)
        {
            context.BeginRequest += this.BeginRequestHandler;
        }

        private void BeginRequestHandler(object sender, EventArgs args)
        {
            HttpContext.Current.Request.Filter = new QQQ1(HttpContext.Current.Request.Filter);
            HttpContext.Current.Request.Filter = new QQQ2(HttpContext.Current.Request.Filter);
        }
    }&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Re: Request.Filter</title><link>http://forums.asp.net/thread/3285316.aspx</link><pubDate>Fri, 10 Jul 2009 06:37:52 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3285316</guid><dc:creator>mulisak</dc:creator><author>mulisak</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3285316.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=27&amp;PostID=3285316</wfw:commentRss><description>&lt;p&gt;I&amp;nbsp;have come across the same problem.&amp;nbsp;Request.Filter is just not working,&amp;nbsp;my custom stream class&amp;nbsp;code is never called, though for Response.Filter it works ok.&lt;/p&gt;</description></item><item><title>Re: Request.Filter</title><link>http://forums.asp.net/thread/3258028.aspx</link><pubDate>Thu, 25 Jun 2009 14:33:03 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3258028</guid><dc:creator>unrealimhere</dc:creator><author>unrealimhere</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3258028.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=27&amp;PostID=3258028</wfw:commentRss><description>&lt;p&gt;I was wondering if you have any advice on a problem I am seeing.&amp;nbsp; I am creating an HttpModule where in the OnBeginRequest,&amp;nbsp;I create a wrapper stream passing in the Request.Filter (I tried to pass in the Request.InputStream but when I run my application, I get an HttpException saying The request filter is not valid) into it and then set that wrapper stream as the filter doing something like Request.Filter = myWrapper.&amp;nbsp; In my wrapper class I implement all the Stream methods, with the main one being of course the Read method where I was hoping to grab the bytes that are read and then write them out somewhere else.&amp;nbsp; What is odd is I was expecting that when the InputStream was accessed (which I was doing in my test app in its Application_Begin_Request, it would be indirectly using my filter, but it does not.&amp;nbsp; Is there anything else I need to enable in order for my wrapper class to be enabled as the Filter when InputStream is use on the Request?&lt;/p&gt;
&lt;p&gt;Thanks in advance for any advice!&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;public class RequestLoggingFilter : IHttpModule
        protected void OnBeginRequest(object sender, EventArgs ea) {
            HttpApplication application = (HttpApplication)sender;
            HttpRequestLog httpRequestLog = new HttpRequestLog();
            application.Context.Items.Add(&amp;quot;HttpRequestLog&amp;quot;, httpRequestLog);
            WrapperInputStream wrapperInputStream = new WrapperInputStream(application.Request.Filter);
            httpRequestLog.WrapperInputStream = wrapperInputStream;
            application.Request.Filter = wrapperInputStream;
        }
.....
}


public class WrapperInputStream : Stream{

        public WrapperInputStream(Stream inputStream) {
            mInputStream = inputStream;
            if (inputStream.Length &amp;gt; 0) {
                mOutputStream = new MemoryStream((int)inputStream.Length);
            }
            else {
                mOutputStream = new MemoryStream();
            }
        }

        public override int Read(byte[] buffer, int offset, int count) {
            int readBytes = mInputStream.Read(buffer, offset, count);
            if (readBytes &amp;gt; 0) {
                mOutputStream.Write(buffer, offset, readBytes);
                mDataCaptureStarted = true;
                if (readBytes == count) {
                    mDataCaptureComplete = true;
                }
            }
            else {
                mDataCaptureComplete = true;
            }
            return readBytes;
        }
...
}

public class Global : System.Web.HttpApplication {
        protected void Application_BeginRequest(object sender, EventArgs e) {
            String mBody = &amp;quot;&amp;quot;;
            Stream stream = ((HttpApplication)sender).Request.InputStream;
            int length = (int)stream.Length;
            logger.Info(length);
            try {
                byte[] bytes = new byte[length];
                stream.Read(bytes, 0, length);
                foreach (byte b in bytes) {
                    mBody += (Char)b;
                }
                //StreamReader reader = new StreamReader(((HttpApplication)sender).Request.InputStream);
                //mBody = reader.ReadToEnd();
                //reader.Close();
            }
            catch (Exception ex) {
                mBody = &amp;quot;Error decoding body: &amp;quot; + ex.Message;
            }
            logger.Info(mBody);
        }
...
}&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Request.Filter</title><link>http://forums.asp.net/thread/2967048.aspx</link><pubDate>Thu, 26 Feb 2009 02:51:15 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2967048</guid><dc:creator>Nai-Dong Jin - MSFT</dc:creator><author>Nai-Dong Jin - MSFT</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2967048.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=27&amp;PostID=2967048</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;From your description, you&amp;#39;re wanting to do some certain modification on the Request&amp;#39;s InputStream and also you found using the Request Filter&lt;br /&gt;HttpModule not worked, yes? If there is anything I misunderstood, please feel free to let me know.&lt;br /&gt;&lt;br /&gt;Based on my experience, generally if we&amp;#39;d like to do some general operations on the Request&amp;#39;s InputStream, the only way is just the Filter&lt;br /&gt;httpMoudle. But this way may be somewhat complex because that means we need to directly deal with the raw byte stream of the Request. Here are some tech articles on using the HTTPMODULE to generate Fitler:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#Intercepting Filter&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/library/en-us/dnpatterns/html/DesInterceptingFilte" target="_blank" rel="nofollow"&gt;&lt;font color="#22229c"&gt;http://msdn.microsoft.com/library/en...erceptingFilte&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;r.asp?frame=true&lt;br /&gt;&lt;br /&gt;#Implementing Intercepting Filter in ASP.NET Using HTTP Module&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/library/en-us/dnpatterns/html/ImpInterceptingFilte" target="_blank" rel="nofollow"&gt;&lt;font color="#22229c"&gt;http://msdn.microsoft.com/library/en...erceptingFilte&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;rInASP.asp?frame=true&lt;br /&gt;&lt;br /&gt;#Filtering HTTP Requests with .NET&lt;br /&gt;&lt;a href="http://www.ondotnet.com/pub/a/dotnet/2003/10/20/httpfilter.html" target="_blank" rel="nofollow"&gt;&lt;font color="#22229c"&gt;http://www.ondotnet.com/pub/a/dotnet...ttpfilter.html&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;#HttpRequest.Filter Property&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebHttpRequest" target="_blank" rel="nofollow"&gt;&lt;font color="#22229c"&gt;http://msdn.microsoft.com/library/en...WebHttpRequest&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;ClassFilterTopic.asp?frame=true&lt;br /&gt;&lt;br /&gt;#Build an ASP.NET HttpRequest Log Filter&lt;br /&gt;&lt;a href="http://www.eggheadcafe.com/articles/20030813.asp" target="_blank" rel="nofollow"&gt;&lt;font color="#22229c"&gt;http://www.eggheadcafe.com/articles/20030813.asp&lt;/font&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Request.Filter</title><link>http://forums.asp.net/thread/2956932.aspx</link><pubDate>Sat, 21 Feb 2009 12:58:14 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2956932</guid><dc:creator>k1fathi</dc:creator><author>k1fathi</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2956932.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=27&amp;PostID=2956932</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;Hi,all&lt;br /&gt;I have some problem for changing &amp;#39;Request.InputStream&amp;#39; with &amp;#39;Request.Filter&amp;#39; or any other solution&lt;br /&gt;how can I change my Request&amp;nbsp; InputStream ? before sending data to server.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;example:I wanna Replace the value &amp;quot;txt1&amp;quot; of asp.net textbox contorl coming from &amp;#39;Request.InputStream&amp;#39;, &amp;nbsp;&lt;br /&gt;by &amp;quot;txt2&amp;quot; that created in HttpModule Begin_Request handler .&amp;quot;txt2&amp;quot; must use instead of &amp;quot;txt1&amp;quot; before sending data to server!&lt;br /&gt;is there any solution to change stream of &amp;#39;Request.InputStream&amp;#39; by &amp;#39;Request.Filter&amp;#39;???&lt;/p&gt;</description></item></channel></rss>