One of the features of ASP.NET is that it remembers the state of controls that are on the page throughout the page cycle. It does this automatically for you by creating a hidden field called Viewstate.
This field can often times become very large. This can impact SEO because search engine bots don’t like to wade through lots of code to get to the content. Many SEOs will tell you to optimize your code so as to remove all needless HTML, Javascript and CSS from the page and to use external files whenever possible.
I researched this recently and found a good forum thread on this topic.
http://www.webmasterworld.com/forum47/2044.htm
It goes into several methods for working around ASP.NET’s viewstate for SEO.
The first is to disable viewstate all together:
< %@ Page EnableViewState="false" %>
or
remove the runat=server attribute of the form tag. (I have not tried that)
The second is to minimize the size of the viewstate field by removing the runat=server attribute of all controls you don’t need to remember their state.
The last thing they recommended was to move the viewstate field to the bottom of the page. There is some code there that supposidly did this, but I haven’t tried it. Keep in mind that the post is dated 2004 so I don’t know if it willl work without bugs in ASP.NET 2.0
Here is the excerpt from the post:
Actually…I just found the code in the DNN project…they use it in a base page…if you are not familiar with that it is a class that inherits from Inherits System.Web.UI.Page and then any page you make should inherit from your custom base page. You could also probably copy and past the below code into each of your pages.
' 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 Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim stringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter)
MyBase.Render(htmlWriter)
Dim html As String = stringWriter.ToString()
Dim StartPoint As Integer = html.IndexOf("<input type=""hidden"" name=""__VIEWSTATE""")
If StartPoint />= 0 Then 'does __VIEWSTATE exist?
Dim EndPoint As Integer = html.IndexOf("/>", StartPoint) + 2
Dim ViewStateInput As String = html.Substring(StartPoint, EndPoint - StartPoint)
html = html.Remove(StartPoint, EndPoint - StartPoint)
Dim FormEndStart As Integer = html.IndexOf("") - 1
If FormEndStart >= 0 Then
html = html.Insert(FormEndStart, ViewStateInput)
End If
End If
writer.Write(html)
End Sub
AndrewVos says
Hi Tom,
I couldn’t find any way to contact you, and was wanting to comment on your page entitled “WordPress Permalinks in IIS using Custom 404 Redirect”…
If a user browsed to page: http://url/date/post then they would get redirected to the page including the query string?
So in the end the user would end up on that actual page anyway, and if they copied the link at this time then it wouldn’t be the permalink.
The only use for permalinks in this case is when you click the actual link on the main page?
I haven’t been able to test this yet, because my web host is having some problems with .asp redirects as of this time, so I’m wondering if this is the right solution for me.
Mr Yossu says
Hello,
Your comment about removing the runat=”server” attribute to reduce viewstate size is inaccurate and can lead to all sorts of problems.
Removing the runat attribute will cause any server tag to fail with an error, and will cause run time errors on normal tags that need to be accessed from server-side code.
What you need to do to remove an individual control from the viewstate is to set its EnableViewState property to false. This will remove it, but leave it fully operational. This is the correct way to do it.
Tom says
Thanks – I didn’t try it so I didn’t know. This should be helpful to readers.