0

I have dynamic menus which are created by my clients. I have registered my routes at Application_Start event in global.asax. Now i want to register routes when my clients add new menus. How can i achieve this?

Currently I have registered all old routes at Application_Start event in global.asax.

void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
}

void RegisterRoutes(RouteCollection routes)
{

    string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlConnection sqlCon = new SqlConnection(connectionstring);
    SqlCommand sqlCmd = new SqlCommand("Sch_Sp_GetRegisterRoutes", sqlCon);
    sqlCmd.CommandType = CommandType.StoredProcedure;

    SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
    DataTable dt = new DataTable();

    try
    {
        sda.Fill(dt);
    }
    catch (Exception ex)
    {
    }
    finally
    {
        sqlCon.Close();

    }
    if (dt != null && dt.Rows.Count > 0)
    {
        foreach (DataRow dr in dt.Rows)
        {
            try
            {
                routes.MapPageRoute(dr["Menuname"].ToString().Replace(" ",string.Empty),
              dr["URL"].ToString(),
               "~/" + dr["Pagename"].ToString());
            }
            catch (Exception exx)
            {

            }

        }
    }


}

In admin login i provide a cms like feature to my clients so they can create new pages. Now my question is, how can i register these new page routes in routes?. I do not want to restart my application every time clients add new pages. I just want that when clients add new pages I call a method to register these pages in my routes. How can i achieve this?

Finally I have got a way to fix it. I have Call following method to restart my application..

 System.Web.HttpRuntime.UnloadAppDomain();
angfreak
  • 993
  • 2
  • 11
  • 27
  • possible duplicate of [ASP.Net MVC: Change Routes dynamically](http://stackoverflow.com/questions/2536605/asp-net-mvc-change-routes-dynamically) – dav_i Sep 20 '13 at 10:45
  • @dav_i Sir I have used Asp.net web form please give me soution for this approach.. – angfreak Sep 20 '13 at 10:52
  • appologies, I didn't see the webforms part of your title. What have you tried already? – dav_i Sep 20 '13 at 11:02
  • @dav_i I have not used mvc in my project please guide me for asp.net web forms – angfreak Sep 20 '13 at 12:39
  • What have you tried doing? Note your question has been put [on-hold]: please read http://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist. – dav_i Sep 20 '13 at 13:30
  • @dav_i Please see my question I have edited it. – angfreak Sep 21 '13 at 05:40

1 Answers1

0

Now I have used following code to restart my application by which newly created urls registered in routes.

 System.Web.HttpRuntime.UnloadAppDomain();
angfreak
  • 993
  • 2
  • 11
  • 27
  • I added code to my RouteConfig file to pull from the Database and add routes defined there to the Routes table (using routes.MapPageRoute). Then in my admin page where routes are created, I included a link that runs the System.Web.HttpRuntime.UnloadAppDomain() method which calls the RegisterRoutes function again. Works like a charm. – yougotiger Mar 29 '18 at 15:01