Forum Moderators: open

Message Too Old, No Replies

asp.net viewstate bad for seo?

         

villan

6:45 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



has anyone had experience with the viewstate attribute in .net and its effects on seo? one of my clients sites uses it quite a bit, storing datagrid information and the like in it, creating a string that is eight thousand bytes long - before any content. this cannot be the best way to do things, are there any alternatives without rewriting the underlying code?

bcolflesh

6:49 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<%@ Page EnableViewState="false" %>

TheNige

8:59 pm on Aug 4, 2004 (gmt 0)

10+ Year Member



turn off viewstate on controls that don't use it. You can also move the viewstate hidden input to the bottom of the page with some code....not sure how but it can be done.

agerhart

9:02 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also move the viewstate hidden input to the bottom of the page with some code

Do you actually know that this can be done? I've been told a number of times that the above statement is not true.

TheNige

3:18 am on Aug 5, 2004 (gmt 0)

10+ Year Member



Yes it can be done. DotNetNuke (do google search on them) do it just for this SEO reason. I believe either in the render or pre-render event they take the hidden input control and move it to the bottom of the html.

It is an open-source project so you could look through the code to see how they do it...or ask in the forums at the ASP.Net website...there is a DNN section there.

TheNige

3:29 am on Aug 5, 2004 (gmt 0)

10+ Year Member



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("</form>") - 1
If FormEndStart >= 0 Then
html = html.Insert(FormEndStart, ViewStateInput)
End If
End If
writer.Write(html)
End Sub

Easy_Coder

12:56 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



-->asp.net viewstate bad for seo?

I've not seen any posts that show evidence of this being bad for SEO. Has anyone?

If your not using server side controls or binding you can remove the runat=server tag from the form... that will remove the viewstate field.

sachin_ch

5:41 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



i don't think it effects in anyway your SEO

agerhart

5:46 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) When the viewstate on the page weighs between 5 and 10K, it becomes a problem.
2) When the extrememly large viewstate code is at the top of the code, it pushes down the money content that you want at the top.

Thanks TheNige, I'll look into this.

duckhunter

3:13 am on Aug 6, 2004 (gmt 0)

10+ Year Member



One way to think about it is that the viewstate grows with the number of Session variables as well as a few other points of data gathered during the surfer's visit.

If you have few or no Session objects when the visitor first lands on the site when the spider hits the money pages it never sees a real long string like a customer would shopping around the site and adding items into their cart, generating cookie content, entering data into forms, etc.

agerhart

12:04 am on Aug 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TheNige,

Just wanted to say thanks. That code worked wonderfully. We've just implemented this across our site.

tomasz

6:09 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



Excellent post, thanks

Small Website Guy

10:35 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



(1) The Viewstate INPUT is "hidden", and I'm sure that the Google spider is smart enough to just ignore the whole thing because it only looks at stuff that's visible to the user.

(2) Viewstate is automatically enabled on all controls you stick on your form, and in most cases you don't need it enabled, so you should go around turning it off where it's not needed. This probably won't help your SEO that much, but it will save you bandwidth and help the pages load faster.

TheNige

9:01 pm on Aug 16, 2004 (gmt 0)

10+ Year Member



No problem. If you guys haven't checked out DotNetNuke or even the ASP.Net fourms (now Community Server Forums) open source projects then I highly recommend it as you can see many "best" practices and neat tricks with ASP.Net.

The core teams are all very good programmers and the Community Server Forums even helped influence some features that are going to be in ASP 2.0

Do searches on them in Google.

raywood

1:57 pm on Aug 17, 2004 (gmt 0)

10+ Year Member



I tried using ViewState for paging a datagrid. Horrible performance. I was also concerned about search engines. Then I found this article [eggheadcafe.com...] .
Now I'm using session variable for paging. Maybe eats up a lot of server resources when there are lots of users on my search pages, but performance is still far better.