Skip to content

Instantly share code, notes, and snippets.

@falafelsoftware
Last active August 29, 2015 14:01
Show Gist options
  • Save falafelsoftware/ecaf57e5d43549df901a to your computer and use it in GitHub Desktop.
Save falafelsoftware/ecaf57e5d43549df901a to your computer and use it in GitHub Desktop.
Remove Sitefinity WebResource axd
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;
using HtmlAgilityPack;
using Telerik.Sitefinity.Configuration;
namespace Sitefinity.Framework.Web.Controls
{
/// <summary>
/// A base class that will be used for the master pages to remove the Telerik Web resource
/// </summary>
public class MasterBase : MasterPage
{
protected override void Render(HtmlTextWriter writer)
{
//Render normally in the backend or if the setting is false
if (this.IsBackend() || this.IsDesignMode())
{
base.Render(writer);
return;
}
var tw = new StringWriter();
var htw = new HtmlTextWriter(tw);
base.Render(htw);
//Get page source
var pageSource = tw.ToString();
//Load the html document to use HtmlAgilityPack
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(pageSource);
if (htmlDoc.DocumentNode == null) return;
//Get the telerik UI web resource scripts
var bodyNode = htmlDoc.DocumentNode.SelectNodes("//script").Where(s => s.GetAttributeValue("src", string.Empty).Contains(Constants.TELERIK_WEBUI_WEBRESOURCE) || string.IsNullOrEmpty(s.GetAttributeValue("src", string.Empty)));
foreach (var node in bodyNode)
{
//Delete the scripts if there is a match
node.ParentNode.RemoveChild(node);
}
pageSource = htmlDoc.DocumentNode.OuterHtml;
//render the outer html
writer.Write(pageSource);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment