Hi,
I have a global.asax class file where I am placing the seo url routing concept like this:
private static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("", "", "~/Default.aspx");
routes.MapPageRoute("", "{categorySEOName}", "~/Pages.aspx");
routes.MapPageRoute("", "{categorySEOName}/{subcategorySEOName}", "~/Pages.aspx");
}
and this how I am getting the data from database and rewrite my url:
public void LoadMenu()
{
CategoryInfo _CateogyInfo = new CategoryInfo();
SubCategoryInfo _SubcateoryInfo = new SubCategoryInfo();
List<CategoryInfo> categoryList = _CateogyInfo.GetCategory().ToList<CategoryInfo>();
StringBuilder sb = new StringBuilder();
string appname = Request.ApplicationPath == "/" ? "" : Request.ApplicationPath.ToString();
sb.Append("<ul id='nav'>");
foreach (CategoryInfo category in categoryList)
{
string seourl = string.Format("{0}/{1}", appname, category.CategorySEOName);
sb.Append("<li><a class='hsubs' href=" + seourl + ">" + category.CategoryName + "</a>");
_SubcateoryInfo.CategoryId = category.CategoryId != null ? category.CategoryId : 0;
_SubcateoryInfo.CategoryId = Convert.ToInt32(Request["categoryId"]);
List<SubCategoryInfo> SubcategoryList = _SubcateoryInfo.GetSubCategoryByCategoryId().ToList<SubCategoryInfo>();
if (SubcategoryList.Count > 0)
{
sb.Append("<ul class='subs'>");
foreach (SubCategoryInfo subCategory in SubcategoryList)
{
seourl = string.Format("{0}/{1}/{2}", appname, category.CategorySEOName, subCategory.SubCategorySEOName);
sb.Append("<li><a href=" + seourl + ">" + subCategory.SubCategoryName + "</a></li>");
}
sb.Append("</ul>");
}
}
sb.Append("</ul>");
MenuSubMenu.Text = sb.ToString();
}
Now my kestion is how can I get a categoryId requested by the user to pass it from page to page.
Like once a user click on category I want to get that categoryId and pass it as the request["CategoryId"] to my next page.
This is the way I used to get the requested Id :
app.Context.RewritePath("~/Category.aspx?Id=" + url[url.Length - 2] + "&name=" + url[url.Length - 1].Replace(".aspx", "") + "&type=category");
Now If I want to get the Id requested I will pass it to a variable like this:
_SubCategoryInfo.CategoryId = Convert.ToInt32(Request["Id"]);
But as u know this is not seo friendly.
Now I want to use the same idea to get the requested Id using routing concept.