![](/img/trans.png)
[英]How to add routes to a 3rd party asp.net application, when no access to Application_Start is available
[英]Is it possible to add routes other that Application_start Event in asp.net web forms
我有由客户创建的动态菜单。 我已在global.asax
Application_Start
事件中注册了我的路线。 现在我想在我的客户添加新菜单时注册路线。 我怎样才能做到这一点?
目前,我已在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)
{
}
}
}
}
在管理员登录中,我向客户提供了类似于cms的功能,以便他们可以创建新页面。 现在我的问题是, 如何在路线中注册这些新的页面路线? 。 我不想每次客户端添加新页面时都重新启动我的应用程序。 我只希望客户添加新页面时调用一种方法在我的路线中注册这些页面。 我怎样才能做到这一点?
终于我有了解决它的方法。 我有调用以下方法来重新启动我的应用程序。
System.Web.HttpRuntime.UnloadAppDomain();
现在,我已使用以下代码重新启动我的应用程序,通过该应用程序在路由中注册了新创建的url。
System.Web.HttpRuntime.UnloadAppDomain();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.