Dec 20

Rewriting urls in Asp.Net is not a complicated thing if you remember some basic steps:
1. Any request will first go to Application_BeginRequest from Global.asax
2. Your online store must be designed in an easy way:
- categories must be unique by name
- subcategories must be unique by name in the same category (The pair category-subcategory must be unique)
In this way you can have as many levels as you want.

Using this advices, you will have a function that helps your users navigate through levels of categories.
protected void Application_BeginRequest(Object sender, EventArgs e)
{

string fullOrigionalpath = Request.Url.ToString();
string filePath = Request.FilePath.ToString();

if (filePath.ToLower().Contains(“sitemap.html”))
{

//if you have a custom sitemap
HttpContext.Current.RewritePath(Generics.HTTP.AppPath + “Sitemap.aspx”, false);

}
//Generics.Constants.Page_EXT in this case is “.html”
filePath = filePath.Replace(Generics.Constants.Page_EXT, string.Empty);
string originalFilePath = filePath;

string path = Generics.HTTP.AppPath;

//HERE you add your code
//first you can check if filePath  contains a product id. In this case:

path+=”Products.aspx?id_products=”+id_product;

//if filePath is not a product page, than you check your categories
Category categ=Utility.GetCAtegoryByFriendlyName(filePath);
path+=”Category.aspx?id_category=”+categ.id;

//finally you need to rewrite path as needed
HttpContext.Current.RewritePath(path, false);

}

Comments are closed.

Powered By Wordpress - Theme Provided By Wordpress Theme - Credit Loan