是否可以在 Web 表单中添加Application_start事件 asp.net 路由
本文关键字:start 事件 asp 路由 net Application 添加 Web 表单 是否 | 更新日期: 2023-09-27 18:32:03
我有我的客户创建的动态菜单。我已经在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();