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:
Post a Comment