[英]Is it possible to add routes other that Application_start Event in asp.net web forms
I have dynamic menus which are created by my clients. 我有由客户创建的动态菜单。 I have registered my routes at
Application_Start
event in global.asax
. 我已在
global.asax
Application_Start
事件中注册了我的路线。 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. 目前,我已在global.asax的Application_Start事件中注册了所有旧路由。
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. 在管理员登录中,我向客户提供了类似于cms的功能,以便他们可以创建新页面。 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();
现在,我已使用以下代码重新启动我的应用程序,通过该应用程序在路由中注册了新创建的url。
System.Web.HttpRuntime.UnloadAppDomain();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.