using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Web.UI; namespace ChadSoft.Web.ResponseFilters { public class PluggableNavigationResponseFilter : TextProcessingResponseFilter { private readonly Control _navigationControl; public PluggableNavigationResponseFilter(Stream stream, Control navigationControl) : base(stream) { _navigationControl = navigationControl; } protected override string ProcessResponseText(string responseText) { /* * NOTE: When using WebForms, use the line below to put the control in the server form * so you can actually make use of server controls with postback, etc. */ // return Regex.Replace(responseText, "]*>", AppendControlMarkup, RegexOptions.IgnoreCase); // Append the markup of the navigation control at the beginning of the body return Regex.Replace(responseText, "]*>", AppendControlMarkup, RegexOptions.IgnoreCase); } private string AppendControlMarkup(Match m) { var controlMarkup = new StringBuilder(); var writer = new HtmlTextWriter(new StringWriter(controlMarkup)); _navigationControl.RenderControl(writer); return string.Format("{0}\n{1}", m.Value, controlMarkup); } } }