c# - UrlRewriting on Global.asax and SQL Output Caching -


I am displaying UrlRewrite for my main category pages. Converting:

  www.mysite.com/Category.aspx?id=2  

to

  www.mysite .com / dogs  

To do this, I am using Global.asax 's Application_BeginRequest where I make the following code Pseudocode:

  Secure void Application_BeginRequest (Object Sender, EventArgs e) {if (IsCategoryUrl ()) {string CategoryName = ParseCategoryNameFromUrl (Request.Url); String rangeID = getcategoryIdByNameFromDB (category name); Reference. Rear Path ("/ category. Aspx? Id =" + category id); }}  

My questions are:

  1. Is this the correct way to rewrite the URL? (This is the first time I'm doing this).
  2. Almost every request reads this code from DB, is there any way to cash it? The only technique I found for SQL caching was to & lt;% @ page% & gt; The instructions which are not possible on global.asax are required. Any other solution?

Thanks in advance.

There is nothing wrong in caching your database queries for each category name you have a In the dictionary, the ID can be stored as an example that ends after a certain period. This will remove DB calls in this case. As an example:

  glossary & lt; String, int & gt; CategoryIdLookup;  

It can be stored in the HTTP cache and can be recovered, if it is empty (Ie has never been added or exited with the cache) See the correct ID and then rewrite it.


Comments