[英]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.