IHttpModule Filter Html Sharepoint


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: IHttpModule Filter Html Sharepoint

  1. #1
    Join Date
    Dec 2008
    Posts
    3

    IHttpModule Filter Html Sharepoint

    Hi,

    I'm rather new to both ASP.net and Sharepoint and I need to do some filtering of the response output from a Sharepoint application.

    I've read about the possibility to intercept the response in ASP.net applications "just before" it is sent to the client. It succeeded to do that for asp-pages served by Sharepoint, but my problem is that I want to intercept the pure HTML files only.

    I do catch the response but I'm not able to get the call to the overridden write() in my filter. It only works for the asp-pages.

    See the code below. Could somebody please have a look and try to help me out =)
    Code:
    public class MOSSCleanupModule : IHttpModule
    {
       public void Init(HttpApplication app)
       {
          app.ReleaseRequestState += new EventHandler(InstallResponseFilter);
       }
    
      private void InstallResponseFilter(object sender, EventArgs e)
      {
         HttpResponse response = HttpContext.Current.Response;
         HttpRequest request = HttpContext.Current.Request;
         if (response.ContentType == "text/html" && request.Url.AbsolutePath.EndsWith(".htm"))
         {
            Debug.Write("in InstallResponseFilter()");
            response.Filter = new ModifyHtmlContentFilter(response.Filter);
         }
      }
    
      public void Dispose()
      {}
    }
    
    public class ModifyHtmlContentFilter : Stream
    {
       private Stream responseStream;
    
       public ModifyHtmlContentFilter(Stream inputStream)>
       {
          Debug.Write("in ModifyHtmlContentFilter");
          this.responseStream = inputStream;
       }
    
       public override void Write(byte[] buffer, int offset, int count)
       {
          Debug.Write("in custom Write()");
          StringBuilder html = new StringBuilder(System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count));
          this.modifyHtml(html, "..");
          byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(html.ToString());
          responseStream.Write(data, 0, data.Length);
        }
    
       private void modifyHtml(StringBuilder html, string search)
       {
          Debug.Write("in modifyHtml()");
          // Modify the html
       }
    
    #region Filter overrides
    
    public override bool CanRead{get{return true;}
    
    public override bool CanSeek{get{return true;}}
    
    public override bool CanWrite{get{return true;}}
    
    public override void Close(){responseStream.Close();}
    
    public override void Flush(){responseStream.Flush();}
    
    public override long Length{get{return 0;}}
    
    public override long Position{get{return position;}set{position = value;}}
    
    public override long Seek(long offset, SeekOrigin origin){return responseStream.Seek(offset, origin);}
    
    public override void SetLength(long length){responseStream.SetLength(length);}
    
    public override int Read(byte[] buffer, int offset, int count){return responseStream.Read(buffer, offset, count);}
    
    #endregion
    
    }
    }
    Last edited by Hack; 12-29-2008 at 11:55 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Dec 2008
    Posts
    3
    It started working for pure html file when I changed the EventHandler to BeginRequest to catch it earlier in the pipeline.

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by Q1Q View Post
    It started working for pure html file when I changed the EventHandler to BeginRequest to catch it earlier in the pipeline.
    And did this resolve your problem?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Dec 2008
    Posts
    3
    Yes it did.

    Unfortunately I know too little about the Http pipeline in ASP.net to know exactly why it solved the problem.

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Xml + xsl = html 4 email ??
    By Complete in forum XML
    Replies: 0
    Last Post: 12-12-2008, 08:18 AM
  2. how filter source html?
    By jason213123 in forum Web
    Replies: 2
    Last Post: 09-09-2008, 04:08 AM
  3. Replies: 0
    Last Post: 03-10-2008, 11:41 AM
  4. Importing xslt into 1 master xslt then to html
    By Patrick Long in forum XML
    Replies: 1
    Last Post: 03-01-2002, 02:47 PM
  5. get specific filter after click on html row
    By Bahi in forum Architecture and Design
    Replies: 0
    Last Post: 02-12-2001, 01:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center