Wednesday, August 27, 2008

User friendly URL in ASP.NET and SEO Page Rank

When you submit your Sitemap to the popular search engines like Google,Yahoo and MSN, make sure that your URL's are user friendly and easy to remember. URLs that are long with tracking id's and session id's might reduce the chance of user selecting the URL. Google also reduces the page rank for URL's with multiple query string parameters.

So we need a way to rewrite the URL from,

For e.g:


With an open source library called URL Rewriter you can achieve this in ASP.NET.

I will cover a sample in my next blog.

Wednesday, August 20, 2008

How to get current node's depth from a Sitemap in ASP.NET2.0?

If you are using treecontrol or menucontrol in ASP.NET 2.0, you can achieve this easily using the built in property.

While i was working on a custom navigation tree control, i wanted to get the depth of the current node from the root. By default ASP.NET 2.0 does not have a property to get the depth. So i wrote a neat little recursion which will calculate the depth for you.

Private Function GetDepth(ByVal current As SiteMapNode) As Integer
  If(Not current.ParentNode Is Nothing) Then
    Return GetDepth(current.ParentNode) + 1
    Return 1
  End If
End Function

Sunday, August 17, 2008

ASP.NET - Master pages and Search Engine Optimization:

We all know that have simplified our life with the introduction of master pages. but what about the Search engine optimization?

How do we handle that. Here are few tips for you to make your site Search engine friendly..

1. TITLE tags.
First important factor that affects your Page rank is your page's title. If you use the title tag on the master page and ignore the title attribute on child page's PAGE directive, Google bot will think all your pages are same and it will either reduce your page rank or will ignore it.

So always use the Child page's TITLE Attribute. There are multiple ways you can archive this,

1. From ASPX Page:


<%@ Page Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="ezSmartAds.Home" Title="Website Promotion -Improve ROI" %>

C# :

protected void Page_Load(object sender, System.EventArgs e)
    this.Page.Title = "Website Promotion -Improve ROI";


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Me.Page.Title = "Website Promotion -Improve ROI"\
End Sub

2. META Tags:

Second important factor is your Meta tags. When users search's on a search engine, Meta description is the one which encourages your users to click on your site.

Here is the explanation from Google on Meta Description:

"Differentiate the descriptions for different pages. Using identical or similar descriptions on every page of a site isn't very helpful when individual pages appear in the web results. In these cases we're less likely to display the boilerplate text. Wherever possible, create descriptions that accurately describe the specific page. Use site-level descriptions on the main home page or other aggregation pages, and use page-level descriptions everywhere else. If you don't have time to create a description for every single page, try to prioritize your content: At the very least, create a description for the critical URLs like your home page and popular pages."

Here is the sample code to add meta tags from code behind.

From Code behind:


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  Dim metaTagAuthor As HtmlMeta = New HtmlMeta
  Dim metaTagKeywords As HtmlMeta = New HtmlMeta
  Dim metaTagDescription As HtmlMeta = New HtmlMeta
  metaTagAuthor.Name = "Author"
  metaTagAuthor.Content = "Your Name" 'Add your name here
  metaTagKeywords.Name = "Keywords"
  metaTagKeywords.Content = "" 'Add all your keywords here
  metaTagDescription.Name = "Description"
  metaTagDescription.Content = "" 'Add you webpage's description here
End Sub


protected void Page_Load(object sender, System.EventArgs e)
  HtmlMeta metaTagAuthor = new HtmlMeta();
  HtmlMeta metaTagKeywords = new HtmlMeta();
  HtmlMeta metaTagDescription = new HtmlMeta();
  metaTagAuthor.Name = "Author";
  metaTagAuthor.Content = "Your Name"; //Add your name here
  metaTagKeywords.Name = "Keywords";
  metaTagKeywords.Content = ""; //Add all your keywords here
  metaTagDescription.Name = "Description";
  metaTagDescription.Content = "";//Add you webpage's description here

Hope you find this article useful. I have implemented the same for one of our websites