문제

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();
도움이 되었습니까?

해결책

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

 System.Web.HttpRuntime.UnloadAppDomain();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top