Click here to Skip to main content
14,878,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have used Framework 4.6.1 and MVC 5. Projecct Architecture-nlayer and dapper is used.

We have facing AcquireRequestState causing slow page load times issue.

C# code -we used SqlCacheDependency for below code
C#
public class AccessMenuController : BaseController
    { 
		public ActionResult AppCount()
        {
            var result = _iAccessMenu.AppCount(Session["Id"]);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
	}	

public int AppCount(int Id)
        {
            try
            {
                List<dbparameter> Params = new List<dbparameter>();
                GenericDAL oGenericDAL = new GenericDAL();
                Params.Add(oGenericDAL.PrepareParameter("@PracticeID", DbType.Int32, Id));              


                return (int)_ISqlCache.GetCacheDataDAL("USP_LiveWidget_GetCounts", Params, "tblLiveWidgetCheckedInVisitCount", "AppointmentCheckinCount:" + Convert.ToString(PracticeId) + ":" + Convert.ToString(ResourceId), "AppointmentCheckinCount", InSyncConvert.ToInt(CatcheExpireTimings.AppointmentCheckinCount)).Rows[0][0];
            }
            catch (Exception)
            {
                throw;
            }
}

public  DataTable GetCacheDataDAL(string StoreProceName, List<dbparameter> SqlParam, string TableName, string cacheName,string KeyName,Int32 CatchExpiredSeconds)
        {
            
            DataTable dtTemp = null;
            object obj = CommonSqlCacheUtilities.GetCacheData(cacheName);
            dtTemp = (DataTable)obj;
            if (dtTemp == null)
            {
               
                dtTemp = new DataTable();
                dtTemp = GetCacheDAL(StoreProceName, SqlParam);
                CommonSqlCacheUtilities.SetCacheData(cacheName, dtTemp,  TableName, KeyName, StoreProceName, SqlParam, CatchExpiredSeconds);
            }
            return dtTemp;
        }
 

  public static object GetCacheData(string cacheName)
        {
            return HostingEnvironment.Cache.Get(cacheName);

        }
        public static void SetCacheData(string cacheName,  object dataSet, string tableName,string KeyName, string StoreProceName, List<dbparameter> SqlParam,Int32 CatchExpiredSeconds)
        {
            //Many articles online state that the following statement should be run only once at the start of the application. 
            //Few articles say the object get replaced if called again with same connection string.
            InSync.Utility.DecryptConnection objDecryption = new InSync.Utility.DecryptConnection();
            string connString = objDecryption.GetConnectionString("SQLConnectionString", false);
            SqlDependency.Start(connString);

            //The following statements needs to be run only once against the connection string and the database table, hence may also be moved to an appropriate place in code.
            SqlCacheDependencyAdmin.EnableNotifications(connString);
            SqlCacheDependencyAdmin.EnableTableForNotifications(connString, tableName);
            SqlCommand sc = new SqlCommand(StoreProceName,new SqlConnection(connString));
            sc.CommandType = CommandType.StoredProcedure;
            
            foreach (var item in SqlParam)
            {
                sc.Parameters.AddWithValue(item.ParameterName,item.Value);
            }                                    

            SqlCacheDependency dependency = new SqlCacheDependency(sc);
            
            HostingEnvironment.Cache.Insert(cacheName, dataSet, dependency, DateTime.Now.AddSeconds(CatchExpiredSeconds), Cache.NoSlidingExpiration, CacheItemPriority.Normal,null);

        }
        public static void RemoveCacheData(string CacheName)
        {
            HostingEnvironment.Cache.Remove(CacheName);
        }

js code
JavaScript
function AppCount() {
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: getBaselocation("AccessMenu/AppCount"),
        async: true,
        data: {
        },
        dataType: "json",
        success: function (response) {
		}
	});
}
$(document).ready(function () {
 setInterval(function() {
      
            AppCount();
       
    },
        55003);
})

Please help me to resolve my issue

What I have tried:

we have migrate framework from 4.6.1 to 4.7.2 and trying to implement
[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] in controller level and session.Required inside controller, but facing TempData null issue when redirect controller to controller. we used Keep method also.
Posted
Updated 11-Aug-20 21:59pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900