简体   繁体   English

是否可以在asp.net Web表单中添加除Application_start事件以外的路由

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

相关问题 当无法访问Application_Start时如何向第三方asp.net应用程序添加路由 - How to add routes to a 3rd party asp.net application, when no access to Application_Start is available ASP.NET应用程序是否可以向启动Application_Start事件的用户显示等待屏幕? - Is there a way for an ASP.NET app to show a wait screen to the user that kicks off the Application_Start event? asp.net application_start事件中的问题……它非常非常慢……可能是什么原因? - problem in asp.net application_start event…its very very slow…what could be the reason? ASP.net Application_Start捕获计时器中的异常 - ASP.net Application_Start catch exception in timer 访问在Application_Start ASP.NET MVC 3中创建的变量 - Accessing Variables Created In Application_Start ASP.NET MVC 3 ASP.NET MVC3调试Application_Start - ASP.NET MVC3 Debugging Application_Start asp.net:调试缓慢-始终触发application_start - asp.net: slow debugging - always fire application_start 如何在Application_Start事件中向网页添加控件 - How Add Control to web page in Application_Start event 可以检查是否触发了Application_Start事件? - Possible to check if Application_Start Event fired? 在asp.net中托管套接字服务 - 与application_start和application_end有关 - Hosting a socket service in asp.net - issues with application_start & application_end
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM