I am performing UrlRewrite for my main categories. Conversion:
www.mysite.com/Category.aspx?id=2
to
www.mysite.com/Dogs
For this, I use Global.asax
Application_BeginRequest
where I execute the following code (pseudocode):
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (IsCategoryUrl())
{
string CategoryName = ParseCategoryNameFromUrl(Request.Url);
string CategoryId = GetCategoryIdByNameFromDB( CategoryName );
Context.RewritePath("/Category.aspx?id=" + CategoryId);
}
}
My questions:
- Is this the right way to do Url Rewriting? (This is the first time I do this).
- This code causes reading from the database from almost EVERY request, is there any way to cache it? The only method I found for SQL Caching required a directive
<%@ Page %>
that is not possible in Global.asax
. Any other solution?
Thanks in advance.
source
share