UrlRewriting for caching Global.asax and SQL output

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_BeginRequestwhere 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.

+3
source share
1 answer

. , . . :

Dictionary<string, int> categoryIdLookup;

HTTP , null (, ), , .

+2

Source: https://habr.com/ru/post/1702547/


All Articles