ranio Ответов: 1

Как уменьшить медлительность загрузки страниц под меню после входа в систему в C#?


Я хочу уменьшить медлительность загрузки страниц под меню в c# после входа в систему. Я показываю 4 приложения в одном кармане, и создание меню выполняется динамически. Мы вызываем их при загрузке каждой страницы. Проверил SP и никакой задержки в получении данных.

Что я уже пробовал:

Основной код выглядит следующим образом:
#region PopulateMenu
    /// <summary>
    /// PopulateMenu
    /// </summary>
    private void PopulateMenu(DataSet DSAdmin)
    {

        //Here a dataset is created for menu and the same is saved to a session variable
        DataSet ds = new DataSet();
        ScreenControls objScreen_Controls = new ScreenControls();

        string ErrorCode = string.Empty;
        string ErrorMsg = string.Empty;
        string LoginId = Session["LOGINID"].ToString();

        string strUserID = Session["USER"].ToString();
        decimal Role = Convert.ToDecimal(Session["ROLE"].ToString());

        if (ConfigurationManager.AppSettings["WinAuth"].ToString() == "True")
            ds = objScreen_Controls.FetchRoleMenuByLoginId(LoginId, CheckCommonAdmin(), ref ErrorCode, ref ErrorMsg);
        else
            ds = objScreen_Controls.FetchRoleMenu(Role, ref ErrorCode, ref ErrorMsg);


        if (isCommonAdmin)
            ds.Tables[0].Merge(DSAdmin.Tables[0]);
        //Set dataset/table names

        if (ds.Tables.Count > 0)
        {
            ds.DataSetName = "Menus";
            ds.Tables[0].TableName = "Menu";
            ds.Tables[0].Columns[0].ColumnName = "MenuID";
            ds.Tables[0].Columns[1].ColumnName = "Text";
            ds.Tables[0].Columns[2].ColumnName = "Value";
            ds.Tables[0].Columns[3].ColumnName = "ParentID";
            ds.Tables[0].Columns[4].ColumnName = "NavigURL";

            //Dynamic Relation setup
            DataRelation relation = new DataRelation("ParentChild",
                    ds.Tables["Menu"].Columns["MenuID"],
                    ds.Tables["Menu"].Columns["ParentID"], true);

            relation.Nested = true;

            //Menu stored in to Session variable
            Session["USER_MENU"] = ds;

                bool MenuStatus = false;

            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ds.Relations.Add(relation);
                    xmlDataSource.Data = null;
                    mnuHeader.Items.Clear();
                    //Assign to Menu Data Source
                    xmlDataSource.Data = ds.GetXml();
                    MenuStatus = true;
                }
            }

            mnuHeader.Visible = MenuStatus;
        }

        ds.Dispose();
    }

    private void PopulateALLMenu(ref DataSet ds)
    {

        //Here a dataset is created for menu and the same is saved to a session variable
        ds = new DataSet();
        ScreenControls objScreen_Controls = new ScreenControls();
        DataSet dsFTS = new DataSet();
        DataSet dsDDS = new DataSet();
        DataSet dsWPS = new DataSet();
        DataSet dsICCS = new DataSet();
        string ErrorCode = string.Empty;
        string ErrorMsg = string.Empty;
        string LoginId = Session["LOGINID"].ToString();

        string strUserID = Session["USER"].ToString();
        decimal Role = Convert.ToDecimal(Session["ROLE"].ToString());

        DataTable dt = new DataTable();

        dt.Columns.Add("MenuID", System.Type.GetType("System.Decimal"));

        dt.Columns.Add("Text", System.Type.GetType("System.String"));
        dt.Columns.Add("Value", System.Type.GetType("System.String"));
        dt.Columns.Add("ParentID", System.Type.GetType("System.Decimal"));
        dt.Columns.Add("NavigURL", System.Type.GetType("System.String"));
        dt.Columns.Add("SORT_ORDER", System.Type.GetType("System.Decimal"));

        DataRow row1;
        //row1["MenuID"] = 10000;

        //row1["Text"] = ApplicationNames.WPS.ToString();
        //row1["Value"] = ApplicationNames.WPS.ToString();
        //row1["ParentID"] = DBNull.Value;
        //row1["NavigURL"] = DBNull.Value;
        //row1["SORT_ORDER"] = 0;

        //dt.Rows.Add( row1 );

        //ds.Tables.Add( dt );

        //row1 = ds.Tables[0].NewRow( );


        if (CheckSuperAdmin())
        {
          

            if (ConfigurationManager.AppSettings["WinAuth"].ToString() == "True")
            {

                dsFTS = objScreen_Controls.FetchFTSRoleMenuByLoginId(LoginId,false, ref ErrorCode, ref ErrorMsg);
                //dsWPS =objScreen_Controls.FetchRoleMenuByLoginId( LoginId, ref ErrorCode, ref ErrorMsg );
                dsDDS = objScreen_Controls.FetchDDSRoleMenuByLoginId(LoginId, false, ref ErrorCode, ref ErrorMsg);

                dsICCS = objScreen_Controls.FetchICCSRoleMenuByLoginId(LoginId,false, ref ErrorCode, ref ErrorMsg);
                if (isCommonAdmin)
                dsWPS = objScreen_Controls.FetchRoleMenuByLoginId(LoginId, false, ref ErrorCode, ref ErrorMsg);
            }
            else
            {

                dsFTS = objScreen_Controls.FetchFTSRoleMenu(Role, ref ErrorCode, ref ErrorMsg);
                // dsWPS =objScreen_Controls.FetchRoleMenu( Role, ref ErrorCode, ref ErrorMsg );
                dsDDS = objScreen_Controls.FetchDDSRoleMenu(Role, ref ErrorCode, ref ErrorMsg);

                dsICCS = objScreen_Controls.FetchICCSRoleMenu(Role, ref ErrorCode, ref ErrorMsg);
            }
          
            if (isCommonAdmin)
            {
                row1 = dt.NewRow();
                row1["MenuID"] = 9999;

                row1["Text"] = "Application Admin";
                row1["Value"] = "Application Admin";
                row1["ParentID"] = DBNull.Value;
                row1["NavigURL"] = DBNull.Value;
                row1["SORT_ORDER"] = 0;

                // ds.Tables[0].Rows.Add( row1 );

                if (ds.Tables.Count == 0)
                {
                    dt.Rows.Add(row1);

                    ds.Tables.Add(dt);
                }
                else
                    ds.Tables[0].Rows.Add(row1);

                if (dsWPS.Tables[0].Rows.Count > 0)
                {
                    row1 = dt.NewRow();
                    row1["MenuID"] = 10000;

                    row1["Text"] = PaymentHub_NeSTBLL.ApplicationNames.WPS.ToString();
                    row1["Value"] = PaymentHub_NeSTBLL.ApplicationNames.WPS.ToString();
                    row1["ParentID"] = isCommonAdmin ? "9999" : (object)DBNull.Value;
                    row1["NavigURL"] = ResolveUrl(PaymentHub_NeSTBLL.Common.GetMainPage(PaymentHub_NeSTBLL.ApplicationNames.WPS.ToString(), Session["ROLE_CODE"].ToString(), false));
                    row1["SORT_ORDER"] = 0;


                    if (ds.Tables.Count == 0)
                    {
                        dt.Rows.Add(row1);

                        ds.Tables.Add(dt);
                    }
                    else
                        ds.Tables[0].Rows.Add(row1);
                    foreach (DataRow row in dsWPS.Tables[0].Select("ParentID IS NULL"))
                    {
                        row[3] = "10000";
                    }

                    dsWPS.Tables[0].AcceptChanges();
                    ds.Tables[0].Merge(dsWPS.Tables[0]);

              
                }
            }

            if (dsFTS.Tables[0].Rows.Count > 0)
            {
                row1 = dt.NewRow();
                row1["MenuID"] = 20000;

                row1["Text"] = PaymentHub_NeSTBLL.ApplicationNames.FTS.ToString();
                row1["Value"] = PaymentHub_NeSTBLL.ApplicationNames.FTS.ToString();
                row1["ParentID"] = isCommonAdmin ? "9999" : (object)DBNull.Value;
                row1["NavigURL"] = ResolveUrl(PaymentHub_NeSTBLL.Common.GetMainPage(PaymentHub_NeSTBLL.ApplicationNames.FTS.ToString(), Session["ROLE_CODE"].ToString(), false));
                row1["SORT_ORDER"] = 0;

                // ds.Tables[0].Rows.Add( row1 );
                if (ds.Tables.Count == 0)
                {
                    dt.Rows.Add(row1);

                    ds.Tables.Add(dt);
                }
                else
                    ds.Tables[0].Rows.Add(row1);

                foreach (DataRow row in dsFTS.Tables[0].Select("ParentID IS NULL"))
                {
                    row[3] = "20000";
                }

                dsFTS.Tables[0].AcceptChanges();
                ds.Tables[0].Merge(dsFTS.Tables[0]);
            }



            //if ( dsWPS.Tables[0].Rows.Count>0 )
            //{

            // foreach ( DataRow row in dsWPS.Tables[0].Select( "ParentID IS NULL " ) ) { row[3] =
            // "10000"; }

            //    dsWPS.Tables[0].AcceptChanges( );
            //    ds.Tables[0].Merge( dsWPS.Tables[0] );
            //}


            if (dsDDS.Tables[0].Rows.Count > 0)
            {
                row1 = dt.NewRow();
                row1["MenuID"] = 30000;

                row1["Text"] = PaymentHub_NeSTBLL.ApplicationNames.DDS.ToString();
                row1["Value"] = PaymentHub_NeSTBLL.ApplicationNames.DDS.ToString();
                row1["ParentID"] = isCommonAdmin ? "9999" : (object)DBNull.Value;
                row1["NavigURL"] = ResolveUrl(PaymentHub_NeSTBLL.Common.GetMainPage(PaymentHub_NeSTBLL.ApplicationNames.DDS.ToString(), Session["ROLE_CODE"].ToString(), false));
                row1["SORT_ORDER"] = 0;
               

                if (ds.Tables.Count == 0)
                {
                    dt.Rows.Add(row1);

                    ds.Tables.Add(dt);
                }
                else
                    ds.Tables[0].Rows.Add(row1);
                foreach (DataRow row in dsDDS.Tables[0].Select("ParentID IS NULL"))
                {
                    row[3] = "30000";
                }

                dsDDS.Tables[0].AcceptChanges();
                ds.Tables[0].Merge(dsDDS.Tables[0]);
            }
            if (dsICCS.Tables[0].Rows.Count > 0)
            {
                row1 = dt.NewRow();
                row1["MenuID"] = 40000;

                row1["Text"] = "ICCS";
                row1["Value"] = "ICCS";
                row1["ParentID"] = isCommonAdmin ? "9999" : (object)DBNull.Value;
                row1["NavigURL"] = ResolveUrl(PaymentHub_NeSTBLL.Common.GetMainPage(PaymentHub_NeSTBLL.ApplicationNames.ICCSEdge.ToString(), Session["ROLE_CODE"].ToString(), false));
                row1["SORT_ORDER"] = 0;
              


                if (ds.Tables.Count == 0)
                {
                    dt.Rows.Add(row1);

                    ds.Tables.Add(dt);
                }
                else
                    ds.Tables[0].Rows.Add(row1);
                foreach (DataRow row in dsICCS.Tables[0].Select("ParentID IS NULL"))
                {
                    row[3] = "40000";
                }

                dsICCS.Tables[0].AcceptChanges();
                ds.Tables[0].Merge(dsICCS.Tables[0]);
            }

           


            if (dsDDS.Tables[0].Rows.Count == 0 && dsFTS.Tables[0].Rows.Count == 0 && dsICCS.Tables[0].Rows.Count == 0 )
            {
                ds.Tables.Add(dt);
            }
        }
        else
            ds.Tables.Add(dt);

       
            
        //Set dataset/table names
        DataTable dt1 = ds.Tables[0].Copy();
        if (ds.Tables.Count > 0)
        {
            ds.DataSetName = "Menus";
            ds.Tables[0].TableName = "Menu";
            ds.Tables[0].Columns[0].ColumnName = "MenuID";
            ds.Tables[0].Columns[1].ColumnName = "Text";
            ds.Tables[0].Columns[2].ColumnName = "Value";
            ds.Tables[0].Columns[3].ColumnName = "ParentID";
            ds.Tables[0].Columns[4].ColumnName = "NavigURL";

            //Dynamic Relation setup
            DataRelation relation = new DataRelation("ParentChild",
                    ds.Tables["Menu"].Columns["MenuID"],
                    ds.Tables["Menu"].Columns["ParentID"], true);

            relation.Nested = true;

            // ds.Tables[0].AsEnumerable().CopyToDataTable(dt1,LoadOption.OverwriteChanges);

            //Menu stored in to Session variable
            Session["USER_MENU_ALL"] = dt1;


            //DataColumn dc = new DataColumn("NavigURL");
            //dc.DataType = typeof(string);
            //dc.DefaultValue = DBNull.Value;

            //ds.Tables[0].Columns.Remove("NavigURL");
            //ds.Tables[0].Columns.Add(dc);


            bool MenuStatus = false;

            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ds.Relations.Add(relation);
                    xmlDataSource_All.Data = null;
                    mnuHeaderWPSFTSDDS.Items.Clear();
                    //  mnuCommonAdmin.Items.Clear();
                    //Assign to Menu Data Source
                    if (!isCommonAdmin)
                        xmlDataSource_All.Data = ds.GetXml();
                    MenuStatus = true;
                }
            }

            mnuHeaderWPSFTSDDS.Visible = !isCommonAdmin;
          // mnuCommonAdmin.Visible = isCommonAdmin;
        }

        ds.Dispose();
    }
    #endregion


ИП за то же самое

/************************************************************              
Module    : WPS           
Author    : Venu Thomas              
Date    : 24-Oct-2013             
Modified   :               
Name    : [FETCH_MENUS_BY_LOGINID]              
Description   : SELECT MENU Records              
Parameters   : @p_ROLEID, @p_error_code, @p_error_msg              
Tables    : MENUS, SCREENRIGHTS              
Associated PL/SQLs :               
Warnings   :              
See Also   :               
exec [FETCH_MENUS_BY_LOGINID] 'Admin.Maker',false,0,0    
************************************************************/  
  
CREATE PROCEDURE [dbo].[FETCH_MENUS_BY_LOGINID] (@p_LoginID varchar(50)  
, @p_IsCommon bit  
, @p_error_code nvarchar(10) OUTPUT  
, @p_error_msg nvarchar(1000) OUTPUT -- Error Message out              
)  
AS  
        DECLARE @error varchar(40);  
  
        BEGIN TRY;  
                DECLARE @p_WPS_ROLEID decimal(18, 0);  
                --DECLARE  @p_FTS_ROLEID DECIMAL(18,0);    
                --DECLARE  @p_DDS_ROLEID DECIMAL(18,0);    
  
                SET @p_WPS_ROLEID = (SELECT  
                        R.RoleId  
                FROM Users AS U  
                INNER JOIN ROLES AS R  
                        ON U.RoleId = R.ROLEID  
                WHERE U.LoginId = @p_LoginID  
                AND U.[Active] = 1  
                AND U.IsDeleted = 0);  
  
                -- SET @p_FTS_ROLEID=  (SELECT  R.RoleId FROM FTS_BARCLAYS_NEW.[dbo].Users AS U INNER JOIN FTS_BARCLAYS_NEW.[dbo].ROLES AS R ON U.RoleId = R.ROLEID      
                --WHERE U.LoginId = @p_LoginID AND U.[Active] = 1 AND U.IsDeleted = 0);    
  
                -- SET @p_DDS_ROLEID=  (SELECT  R.RoleId FROM DTT_BARCLAYS.[dbo].Users AS U INNER JOIN DTT_BARCLAYS.[dbo].ROLES AS R ON U.RoleId = R.ROLEID      
                --WHERE U.LoginId = @p_LoginID AND U.[Active] = 1 AND U.IsDeleted = 0);    
  
                --WITH Temp_Menu  AS(    
                --  Select 10000 as MenuId, 'WPS' as Text, 'WPS' as Value, NULL as ParentId, NULL as NavigURL, '0' as SORT_ORDER    
                --union all    
  
                SELECT  
                        10000 + M.MenuId AS MenuID,  
                        M.Text AS Text,  
                        CAST(10000 + M.MenuId AS varchar) AS Value,  
                        10000 + M.ParentID AS [ParentID],  
                        'WPS' + M.NavigURL AS NavigURL,  
                        M.SORT_ORDER  
                FROM Menus AS M  
                WHERE M.SCREENID IS NULL  
                AND dbo.IsParentMenu(@p_WPS_ROLEID, M.MenuId) = 1  
                AND IsCommon = @p_IsCommon  
                UNION ALL  
  
  
  
                SELECT  
                        10000 + M.MenuId AS MenuID,  
                        M.Text AS Text,  
                        CAST(10000 + M.MenuId AS varchar) AS Value,  
                        10000 + M.ParentID AS [ParentID],  
                        CASE IsCommon  
                                WHEN 1 THEN 'AdminMenu'  
                                ELSE 'WPS'  
                        END + M.NavigURL AS NavigURL,  
                        M.SORT_ORDER  
                FROM Menus AS M  
                INNER JOIN SCREENRIGHTS AS S  
                        ON M.SCREENID = S.SCREENID  
                        AND S.ROLEID = @p_WPS_ROLEID         --  AND M.IsAdmin IS NULL    
                        AND (S.ADDALLOWED = 'Y'  
                        OR S.EDITALLOWED = 'Y'  
                        OR S.DELETEALLOWED = 'Y')  
                        AND IsCommon = @p_IsCommon  
                ORDER BY M.SORT_ORDER  
  
  
                SET @error = @@error  
                IF @error <> 0  
                        GOTO ERROR_HANDLER--Error handling              
                RETURN (0)  
  
        ERROR_HANDLER:  
                SET @p_error_msg = dbo.GetErrorMessage()    --Unhandled Error              
                SET @p_error_code = 200  
                RETURN (1)  
        END TRY  
        BEGIN CATCH  
                SET @p_error_code = @@ERROR  
                SET @p_error_msg = dbo.GetErrorMessage()  
        END CATCH

1 Ответов

Рейтинг:
1

F-ES Sitecore

Преобразуйте свое меню в пользовательский элемент управления и реализуйте кэширование вывода

Кэширование пользовательских элементов управления : ASP.NET[^]


ranio

Есть ли какое-либо другое решение, чтобы уменьшить медлительность без преобразования меню в пользовательский контроль, так как временные рамки меньше.

F-ES Sitecore

Вы можете реализовать конечную структуру данных, которую используете для привязки меню к using normal asp.net механизмы кэширования, доступные в System.Web.Caching