Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - IHttpModule Filter Html Response Sharepoint

 
Thread Tools Search this Thread
Old 12-29-2008, 01:50 PM   #1
Default IHttpModule Filter Html Response 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 =)

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.GetStr ing(buffer, offset, count));
this.modifyHtml(html, "..");
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(html.ToStri ng());
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

}
}


Q1Q
Q1Q is offline   Reply With Quote
Old 12-30-2008, 09:54 AM   #2
Q1Q
Junior Member
 
Join Date: Dec 2008
Posts: 2
Default
It started working for pure html file when I changed the EventHandler to BeginRequest to catch it earlier in the pipeline.


Q1Q
Q1Q is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Different Ping response times sandhyashyamsundar Hardware 1 07-07-2009 06:22 PM
Help on auto conversion from Matlab to vhdl on filter design hardheart Hardware 0 12-07-2007 09:19 AM
Regarding MSTS SharePoint 2007 and WSS 3.0 Application Development Shiva MCTS 6 12-06-2007 06:32 AM
MCTS in SharePoint or .NET 2.0 Web App.,which will be best for car Satyendra MCTS 2 11-28-2007 08:02 AM
MCTS Sharepoint Server or Windows Sharepoint Services RajivI MCTS 2 10-06-2007 01:13 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46