»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books
»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects
»Competition
Community
Winners
Prizes
Write For Us
Members
»Other Resources
Links
Dotnet Resources
|
Search Engine Friendly URL Rewriting in ASP.NETCompanies 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
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 )
}
}
|
This is how it works in our display page we pass the hyperlinks as this display1.aspx , display2.aspx instead of display.aspx?id=1 , display.aspx?id=2
Before a page is displayed it goes through the Application_BeginRequest event if the page has
|