Moving ViewState to bottom of page for Search Engine Optimization

ASP.NET pages with large hidden viewstate at the top of the page is not good for search engine optimization purposes.  One of my colleagues dug up the below code snippet to help with this problem.  Is anyone attacking this problem in a more elegant manner?

/// <summary>
/// This method overrides the Render() method for the page and moves the viewstate
/// from its default location at the top of the page to the bottom of the page for SEO.
/// </summary>
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(etartPoint, endPoint - startPoint);
            int formEndStart = html.IndexOf("</form>");
            if (formEndStart >= 0){ 
                  html = html.Insert(formEndStart, "\n" + viewstateInput);
            }
      }
      writer.Write(html);

}

 

# re: Moving ViewState to bottom of page for Search Engine Optimization

Wednesday, August 25, 2004 1:50 PM by Dave Bettin    
A HttpModule or perhaps even a solution with Response.Filter would be more elegant.

# re: Moving ViewState to bottom of page for Search Engine Optimization

Thursday, August 26, 2004 11:19 AM by Jeff Gonzalez    
Have you verified this is an actual problem?

I think that spiders don't actually see that content because it is marked as hidden.

Might do some research to verify but we went through this exercise and found it to be a moot point.

# re: Moving ViewState to bottom of page for Search Engine Optimization

Thursday, August 26, 2004 11:20 AM by Jeff Gonzalez    
The following link provides a great insight to what spiders and crawlers see on your site. This was featured prominantly at a SEO conference in San Jose that my boss attended this year and last.

<a target="_new" href="http://www.delorie.com/web/lynxview.html">http://www.delorie.com/web/lynxview.html</a>

# re: Moving ViewState to bottom of page for Search Engine Optimization

Thursday, August 26, 2004 11:28 AM by Jeff Gonzalez    
Sorry I'll chime in one last time. One way I have seen viewstate done is storing Viewstate server side.

You can accomplish this using
LoadPageStateFromPersistenceMedium()SavePageStateToPersistenceMedium()

I don't know all of the implications of this because I imagine there could/would be some intense memory churn with viewstate being held on the server. For an application across the internet where bandwidth concerns are an issue this is probably ideal.

# re: Moving ViewState to bottom of page for Search Engine Optimization

Thursday, August 26, 2004 11:29 AM by Jeff Gonzalez    
LOL this reminds me of that movie Swingers with Vince Vaughn and Jon Favreau. Jon Favreau meets a chick at a bar, gets her digits, and calls her the same night. The answering machine cuts off and he calls back, he ends up calling like 5 or 6 times, finally she answers and says &quot;Dont ever call me again, you psycho.&quot;

Hanging up now...

# re: Moving ViewState to bottom of page for Search Engine Optimization

Thursday, November 11, 2004 6:20 AM by David    
typo...

Change etartPoint to startPoint - this line:

html = html.Remove(etartPoint, endPoint - startPoint);

Post a Comment

 
 
Prove you're not a spammer: 
4 + 4 =