This blog is about the dotnet.all types of codes,news about dotnet including asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.ncluding asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.asp.net programming,dot net programming,dotnet programs,dotnet source code,source code.

Free Hosting

Free Hosting

Sunday, November 2, 2008

Search Engine Friendly URL Rewriting in ASP.NET

Companies spend a lot of money on their websites. But they dont get the results they want. Some of them use database driven web pages Unfortunately, most of these database driven web sites rely heavily on parameters to display contents since parameter passing is the easiest way to pass information between web pages. But it comes with a price. Search engines cannot or will not list any dynamic URLS. Dynamic URLs are said to contain elements such as ?, &, %, +, =, $. Hence, the pages which the hyperlinks point to will be ignored by the Web spider indexing the site.


So how do we go about creating search engine friendly urls in ASP.net the answer using Global.asax.


Instead of sending parameters like http://www.dotnetwatch.com/display.aspx?id=1

we want to change it to http://www.dotnetwatch.com/display1.aspx

in the global.asax Application_BeginRequest add this

CODE:
protected void Application_BeginRequest(Object sender, EventArgs e)
{

HttpContext incoming = HttpContext.Current;
string oldpath = incoming.Request.Path.ToLower();
string id; // id requested

// Regular expressions to grab the page id from the pageX.aspx
Regex regex = new Regex(@"display(\d+).aspx", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
MatchCollection filter = regex.Matches(oldpath);

if (filter.Count > 0)
{
// Extract the id and send it to display.aspx
id = filter[0].Groups[1].ToString();
incoming.RewritePath("display.aspx?id=" + id);
}
else
// diplay old path
incoming.RewritePath(oldpath )
}
}

0 comments:

dotnet(.Net) Project Source code Downloads and Tutorials

Email Subscrption



Enter your email address:

Delivered by FeedBurner

Feedburner Count

Blog Archive

Unique Visitor

Design by araba-cı | MoneyGenerator Blogger Template by GosuBlogger