Tabish Usman
Tabish Usman

Reputation: 3250

how to remove the meta tag named "Generator" which Sitefinity generates by default containing the version information?

I want to remove the meta tag <meta name="Generator" content="Sitefinity 9.1.6110.0 SE \"> for which i have already implemented a solution by writing the following code chunk in the master page.

 protected override void Render(HtmlTextWriter writer)
 {
   using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new System.IO.StringWriter()))
     {
       base.Render(htmlwriter);
       string html = htmlwriter.InnerWriter.ToString();
       html = html.Replace("<meta name=\"Generator\" content=\"Sitefinity 8.0.5710.0 PE\" />", "");
       writer.Write((html));
     }
}

But someone suggested me that its not an appropriate solution because of In-memory rendering of entire page, the default masterpage renders the entire page to a string which incurs a performance overhead. If you want to remove headers, you can do so on the ASP.NET Page object level. So i want an other solution of it as suggested can anyone give an other solution?(a performance effective solution)

Upvotes: 1

Views: 1088

Answers (2)

Victor Leontyev
Victor Leontyev

Reputation: 8736

Best way to do that is subscribe to IPagePreRenderCompleteEvent event and remove this control. An example of global.asax code

protected void Application_Start(object sender, EventArgs e)
{
        Telerik.Sitefinity.Abstractions.Bootstrapper.Initialized += Bootstrapper_Initialized;
}
protected void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs args)
{
        if (args.CommandName == "Bootstrapped") {
            EventHub.Subscribe<IPagePreRenderCompleteEvent>(this.OnPagePreRenderCompleteEventHandler);
        }
}
private void OnPagePreRenderCompleteEventHandler(IPagePreRenderCompleteEvent evt)
{
        if (!evt.PageSiteNode.IsBackend)
        {
            var controls = evt.Page.Header.Controls;
            System.Web.UI.Control generatorControl = null; 
            for(int i=0;i< evt.Page.Header.Controls.Count;i++)
            {
                var control = evt.Page.Header.Controls[i];
                if ((control is HtmlMeta) && (control as HtmlMeta).Name == "Generator") {
                    generatorControl = control;
                }
            }
            evt.Page.Header.Controls.Remove(generatorControl);
        }
 }

Upvotes: 3

Ignas
Ignas

Reputation: 4338

Per SF Version meta tag forum thread seems like you can override System.Web.UI.Adapters.ControlAdapter class and add your own logic for meta tag rendering. See the last post.

If that didn't work for you, you could consider caching the generated page, so you don't need to replace and re-render the same page again.

Upvotes: 0

Related Questions