June 2007


ASP.NET and SEO13 Jun 2007 03:37 pm

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

SQL Server12 Jun 2007 02:27 pm

As far as I could tell there was no easy way to query MSSQL to get a list of all of its tables and their respective sizes. I wrote a sql script that does this for you.

It’s below:


declare @RowCount int, @tablename varchar(100)
declare @Tables table (
PK int IDENTITY(1,1),
tablename varchar(100),
processed bit
)
INSERT into @Tables (tablename)
SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' and TABLE_NAME not like 'dt%' order by TABLE_NAME asc

declare @Space table (
name varchar(100), rows nvarchar(100), reserved varchar(100), data varchar(100), index_size varchar(100), unused varchar(100)
)
select top 1 @tablename = tablename from @Tables where processed is null
SET @RowCount = 1
WHILE (@RowCount <> 0)
BEGIN
insert into @Space exec sp_spaceused @tablename
update @Tables set processed = 1 where tablename = @tablename
select top 1 @tablename = tablename from @Tables where processed is null
SET @RowCount = @@RowCount
END

update @Space set data = replace(data, ‘ KB’, ‘’)
update @Space set data = convert(int, data)/1000
update @Space set data = data + ‘ MB’
update @Space set reserved = replace(reserved, ‘ KB’, ‘’)
update @Space set reserved = convert(int, reserved)/1000
update @Space set reserved = reserved + ‘ MB’

select * from @Space order by convert(int, replace(data, ‘ MB’, ‘’)) desc