Keyboard Face
msgbartop
when you find QWERTY imprinted on your cheek – it’s time to go to bed.
msgbarbottom

13 Jun 07 Is ASP.NET Viewstate bad for SEO?

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("&lt;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

23 May 07 Javascript not loading using AJAX for ASP.NET

Microsoft came out with an AJAX library for use with ASP.NET 2.0. They have a great support website located at ajax.asp.net. Lots of great videos and it works easily when you create a new website from scratch.

I ran into trouble when trying to use their AJAX library with an existing website. It wouldn’t give me any errors, the javascript just wouldn’t work with any of the AJAX controls. It was as if the AJAX didn’t exist!

After about an hour of searching and head scratching I figured that it must be web.config’s fault. I found a page that talks about updating your web.config for integrating the AJAX library into your site. Here it is:

http://ajax.asp.net/docs/ConfiguringASPNETAJAX.aspx

I followed all the directions and like magic, my site works with AJAX now! Phew.

24 Mar 06 Regular Expression Search Engine

Wow! This is a great site: RegExLib (Regular Expression Library)

Excuse my exuberance, but I’ve been creating a lot of long regular expressions from scratch lately and it’s time consuming! This is a great resource for anyone wanting to use regular expressions in their code.

28 Dec 05 Yahoo GeoCoding API and Google Maps API

It’s long been on my mind to use the Google Maps API on some of my sites, but the last hurtle has always been getting the raw longitude and latitude to satisfy the Google Maps API. Google Maps allows you to insert their maps into any web page using javascript. The only catch is you have to give it the latitude and longitude. It doesn’t take street addresses. They recommend using a free geocoder (an application that takes a street address and returns a latitude and longitude.), but they don’t give any real recommendations.

Yahoo!, however does have a free geocoder! http://developer.yahoo.net/maps/rest/V1/geocode.html

Matthew Hazlett just wrote a great tutorial on using both of these APIs to create a map application that takes a street address and turns it into a Google Map!
Here’s the link.

http://www.codeproject.com/Ajax/GeoLocation.asp

23 Dec 05 SQL Programming Excuses

If you need a good erudite excuse: http://www.red-gate.com/excusegenerator/Excuses.aspx

21 Dec 05 Logging Client Side JavaScript Errors to the Server – The Code Project – AJAX / Atlas

This is a brilliant idea. Take a look:

Logging Client Side JavaScript Errors to the Server – The Code Project – AJAX / Atlas

14 Dec 05 WordPress Permalinks with Custom 404 Page

As I mentioned in a previous post, WordPress installed on IIS can be somewhat aggravating because it doesn’t have permalink functionality out of the box. You have to jump through several hoops to get it to work. Mine works for the most part now, but it doesn’t work when you click the “next” link on pages that have large numbers of posts.

I’ve been thinking about a possible solution to this. Would it be possible to use a custom 404 page on IIS to act as a intermediary page that does what mod_rewrite would normally. Here’s how it would work:

1. Set IIS to redirect all 404 errors to a custom page that would handle all interpretation of the permalinks. In IIS, you have the option of specifying whether it i s a file, or a url. It must be set to “url” to work. Here’s a page that goes into this theory. http://evolvedcode.net/content/code_smart404/guide-rewrites.asp

2. All that would be left to do then would be to write a page that interpreted the rules that wordpress gives you and redirects accordingly.

Sorry if this was a little confusing, I’ll be trying this out in a week or so and I’ll let you know the results in a clearer format.

Related Threads from WordPress.org
IIS URL Rewrite Rules?
Enabling Search engine Friendly (Optimized ) URLs in IIS Without Mod_rewrite

This also looks to be promising: IIS Mod’s Free URL ReWrite

07 Dec 05 ASP.NET Google AutoComplete (or AutoSuggest)

A while back I wrote a post on an inventory of existing javascript autocomplete controls. I was writing an application that required one and found most of them to be unsuitable for what I was doing. I ended up using WICK (Web Input Completion Kit) an creating my own ASP.NET user control around it.

An article just came out in CodeProject, however that claims to do everything I was looking for. I haven’t had a chance to look at it yet, but when I do, I’ll let you know how it goes.

Here’s the article: http://www.codeproject.com/aspnet/AddingGoogleSuggest.asp

08 Nov 05 Visual Studio Express for Free

Microsoft is celebrating the launch of Visual Studio Express by offering it for free for the first year. This includes their Visual Web Developer 2005 Express Edition. This is a great light-weight tool for .NET 2.0 development. I’ve been using the beta version of it for the past couple of months.

Here’s the link to the download site: http://msdn.microsoft.com/vstudio/express/

01 Oct 05 Turning off IE and Firefox’s AutoComplete Feature

Sometimes it is inconvenient or inappropriate to have the autocomplete feature of IE or FireFox. I found it blocked the custom autocomplete feature I was building for my app. Just add autocomplete="off" to the form to turn it off:

<form id="formSignOn" autocomplete="off" method="post" runat="server"></form>

In ASP.NET I added it by using the following line:
Me. Form.Attributes.Add("autocomplete", "off")