Last post Jun 07, 2011 10:18 PM by Zizhuoye Chen - MSFT
Jun 03, 2011 03:17 AM|thakkermukund123|LINK
If you move your viewstate from the top of the page to the bottom, you will get better search engine spidering.
Step 1 :
Create a class file in App_code folder of your application and name it as "PageBase.cs". Copy following code to the class file.
public class PageBase : System.Web.UI.Page
/// 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. This
/// results in better search engine spidering.
protected override void Render(System.Web.UI.HtmlTextWriter writer)
// Obtain the HTML rendered by the instance.
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
string html = sw.ToString();
// Hose the writers we don't need anymore.
// Find the viewstate.
int start = html.IndexOf(@"<input type=""hidden"" name=""__VIEWSTATE""" );
// If we find it, then move it.
if (start > -1)
int end = html.IndexOf("/>", start) + 2;
strviewstate = html.Substring(start, end - start);
html = html.Remove(start, end - start);
// Find the end of the form and insert it there.
int formend = html.IndexOf(@"</form>") - 1;
html = html.Insert(formend,
// Send the results back into the writer provided.
Step 2 :
Inherit your aspx pages from the base class.
public partial class Page : WebPageBase.PageBase
// Your code here
Jun 07, 2011 10:18 PM|Zizhuoye Chen - MSFT|LINK
Thank you for sharing your experience to us. And also this can be implement by using regular expression.