This is a migrated thread and some comments may be shown as answers.

[Solved] another HttpModule causes Progress to not appear

0 Answers 100 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 28 Jun 2009, 07:22 AM

I have a custom HttpModule that filters out whitespace.  When it is enabled, the progress dialog does not appear.  I can't seem to figure out why.  Here is the code along with the change to web.config.  Please note that the whitespace code isn't even running on the upload.aspx page.  The line of code that causes the progress bar to fail seems to be:

if (app.Request["HTTP_X_MICROSOFTAJAX"] != null) { return; }

 

If I put a "return;" immediately above this line, the progress dialog appears.  If I put a "return;" immediately after this line, the progress dialog does NOT appear.  How does the executing the above line of code cause the progress dialog to fail to appear?

Thanks for any insight into this issue.  For now, I have to disable my whitespace httpmodule.

John

    <httpModules> 
      <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule, Telerik.Web.UI" /> 
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
      <add name="EntityTransactionModule" type="REO.Web.Data.EntityTransactionModule, REO.Web"/>  
      <add name="WhitespaceModule" type="WhitespaceModule"/>  
    </httpModules> 
 

 

 

 

 

 

 

 

#region Using  
 
using System;  
using System.IO;  
using System.Web;  
using System.IO.Compression;  
using System.Text.RegularExpressions;
#endregion  
 
/// <summary>  
/// Removes whitespace from the webpage.  
/// </summary>  
public class WhitespaceModule : IHttpModule  
{
    #region IHttpModule Members  
 
    void IHttpModule.Dispose()  
    {  
        // Nothing to dispose;   
    }  
 
    void IHttpModule.Init(HttpApplication context)  
    {  
        context.BeginRequest += new EventHandler(context_BeginRequest);  
    }
    #endregion  
 
    void context_BeginRequest(object sender, EventArgs e)  
    {  
        HttpApplication app = sender as HttpApplication;  
 
        if (app.Request["HTTP_X_MICROSOFTAJAX"] != null) { return; }  
 
        string rawurl = app.Request.Path.ToLower();  
        if (rawurl.EndsWith(".aspx") && !rawurl.ToLower().EndsWith("upload.aspx"))  
        {  
            app.Response.Filter = new WhitespaceFilter(app.Response.Filter);  
        }  
    }
    #region Stream filter  
 
    private class WhitespaceFilter : Stream  
    {  
 
        public WhitespaceFilter(Stream sink)  
        {  
            _sink = sink;  
        }  
 
        private Stream _sink;  
        private static Regex reg = new Regex(@"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}");
        #region Properites  
 
        public override bool CanRead  
        {  
            get { return true; }  
        }  
 
        public override bool CanSeek  
        {  
            get { return true; }  
        }  
 
        public override bool CanWrite  
        {  
            get { return true; }  
        }  
 
        public override void Flush()  
        {  
            _sink.Flush();  
        }  
 
        public override long Length  
        {  
            get { return 0; }  
        }  
 
        private long _position;  
        public override long Position  
        {  
            get { return _position; }  
            set { _position = value; }  
        }
        #endregion  
 
        #region Methods  
 
        public override int Read(byte[] buffer, int offset, int count)  
        {  
            return _sink.Read(buffer, offset, count);  
        }  
 
        public override long Seek(long offset, SeekOrigin origin)  
        {  
            return _sink.Seek(offset, origin);  
        }  
 
        public override void SetLength(long value)  
        {  
            _sink.SetLength(value);  
        }  
 
        public override void Close()  
        {  
            _sink.Close();  
        }  
 
        public override void Write(byte[] buffer, int offset, int count)  
        {  
            byte[] data = new byte[count];  
            Buffer.BlockCopy(buffer, offset, data, 0, count);  
            string html = System.Text.Encoding.Default.GetString(buffer);  
 
            if (!html.Contains("textarea"))  
            {  
                html = reg.Replace(html, string.Empty);  
            }  
 
            byte[] outdata = System.Text.Encoding.Default.GetBytes(html);  
            _sink.Write(outdata, 0, outdata.GetLength(0));  
        }
        #endregion  
 
    }
    #endregion  
}  
 

 

 

No answers yet. Maybe you can help?

Tags
Upload (Obsolete)
Asked by
John
Top achievements
Rank 1
Share this question
or