Welcome to WebmasterWorld Guest from 54.197.130.93

Forum Moderators: ocean10000

Message Too Old, No Replies

asp.net viewstate bad for seo?

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

New User

10+ Year Member

joined:June 17, 2004
posts:13
votes: 0


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?
6:49 pm on Aug 4, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2003
posts:2355
votes: 0


<%@ Page EnableViewState="false" %>
8:59 pm on Aug 4, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 30, 2003
posts:374
votes: 0


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.
9:02 pm on Aug 4, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member agerhart is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 29, 2001
posts:2945
votes: 0


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.

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

Preferred Member

10+ Year Member

joined:Sept 30, 2003
posts:374
votes: 0


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.

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

Preferred Member

10+ Year Member

joined:Sept 30, 2003
posts:374
votes: 0


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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2003
posts:1184
votes: 0


-->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.

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

New User

10+ Year Member

joined:Aug 5, 2004
posts:40
votes: 0


i don't think it effects in anyway your SEO
5:46 pm on Aug 5, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member agerhart is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 29, 2001
posts:2945
votes: 0


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.

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

Preferred Member

10+ Year Member

joined:Oct 28, 2002
posts:506
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member agerhart is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 29, 2001
posts:2945
votes: 0


TheNige,

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

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

Full Member

10+ Year Member

joined:May 15, 2002
posts:236
votes: 0


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

Full Member

10+ Year Member

joined:Mar 13, 2003
posts:335
votes: 0


(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.

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

Preferred Member

10+ Year Member

joined:Sept 30, 2003
posts:374
votes: 0


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.

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

Full Member

10+ Year Member

joined:Feb 19, 2004
posts:207
votes: 0


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members