Kentico SEO - Move Viewstate down the page

28. May 2010 03:21 by Oleg in   //  Tags:   //   Comments

 

To move the Viewstate down the page when using Kentico Portal Model you need to override Render method on the ~\CMSPages\PortalTemplate.aspx.cs file e.g.

    protected override void Render(System.Web.UI.HtmlTextWriter writer) {
        System.IO.StringWriter stringWriter = new System.IO.StringWriter();
        HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
        base.Render(htmlWriter);
        string html = stringWriter.ToString();
        int StartPoint = html.IndexOf("<input type=\"hidden\" name=\"__VIEWSTATE\"");
        if (StartPoint >= 0) {
            int EndPoint = html.IndexOf("/>", StartPoint) + 2;
            string viewstateInput = html.Substring(StartPoint, EndPoint - StartPoint);
            html = html.Remove(StartPoint, EndPoint - StartPoint);
            int FormEndStart = html.IndexOf("</form>");
            if (FormEndStart >= 0) {
                html = html.Insert(FormEndStart, viewstateInput + Environment.NewLine);
            }
        }
        writer.Write(html);
    } 

 

More info on this method can be found here
http://www.hanselman.com/blog/MovingViewStateToTheBottomOfThePage.aspx

 

blog comments powered by Disqus

Webcoda, Web Development & Design, Sydney

Webcoda, Web Developers & Designers Sydney is a Sydney based Web Development company comprising a team of consultants who are experts in all aspects of Microsoft web technology from ASP.Net development to Kentico CMS & SharePoint.

Webcoda has a long history of producing outstanding results for clients large and small. We have helped companies grow from humble beginnings to multi-million dollar enterprises through technology.

We love what we do and this blog is our way of sharing info that we find interesting with the world at large. Please feel free to comment or drop us a line on +612 9370 3636

Month List

Page List