0

Hey guys I am struck with how to do customize routing from our .cs page I know that we can do routing in global.asax using routeCollection.MapPageRoute("Default Page", "Default/{ProductName}/{CategoryName}", "~/Default.aspx");

But i want to do customize url routing from our code behind file,since the name of the page comes from database...how can i do that please help me out guys...!!

1 Answers1

0

You can try the following

Define another route in your global.asax as follows

route.MapPageRoute("page/{pageid}", "~/thefilethatdisplaypage.aspx");

in thefilethatdisplaypage.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
   string pageId = RouteData.Values["pageid"].ToString();
   string content = getPageFromDatabase(pageId);

   pageDisplayControl.Text = content;
}

Though I don't know your implementation, that should give you and idea

codingbiz
  • 26,179
  • 8
  • 59
  • 96
  • Hey I want to add routes in global.asax dynamically..from .aspx.cs page how can i do that..I am asking you that – darshan doshi Jul 04 '12 at 11:11
  • that's not a good practice. why do you want to do this that can be handled in global.asax? Please explain. – codingbiz Jul 04 '12 at 11:33
  • Hey I am preparing CMS System in which pages will be added dynamically for that purpose I need this kind of thing......Hope u have understand... – darshan doshi Jul 04 '12 at 11:46
  • the solution I gave you can handle that. drupal stores page id in database, so you can. I have a CMS like that too and I use `www.mysite.com/page/{pagecode}` where `pagecode=['about-us','contact-us', etc]` and I used this to load the content in a single page. You can also have `www.mysite.com/{pagecode}` for `www.mysite.com/page/about-us` and so on putting more specific route at the bottom of route collection – codingbiz Jul 04 '12 at 12:00
  • okk from your this code string content = getPageFromDatabase(pageId); .....In content there will be the page name....U mean to say that For eg:- pagecode=2 stands for about us...pagecode=3 stands for some other page....Is this way you are saying to me to do this...?? – darshan doshi Jul 04 '12 at 12:18