Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a global.asax class file where I am placing the seo url routing concept like this:

C#
private static void RegisterRoutes(RouteCollection routes)
    {
        //More info about url routing http://www.codeproject.com/Articles/77199/URL-Routing-with-ASP-NET
        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:

XML
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:

C#
_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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900