Esempio n. 1
0
        private void App_PostRequestHandlerExecute(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            if (app.Context.Session == null)
            {
                return;
            }

            var session = app.Context.Session;

            // 枚举Session数据时,可能会造成数据被标记为【已修改】,所以要先把标记拿到,枚举结束后恢复。
            PropertyInfo containerProperty = session.GetType().GetProperty("Container", BindingFlags.Instance | BindingFlags.NonPublic);
            object       stateContainer    = containerProperty.GetValue(session, null);

            FieldInfo sessionItemsField = stateContainer.GetType().GetField("_sessionItems", BindingFlags.Instance | BindingFlags.NonPublic);
            object    sessionItems      = sessionItemsField.GetValue(stateContainer);

            PropertyInfo dirtyProperty = sessionItems.GetType().GetProperty("Dirty", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            bool         dirty         = (bool)dirtyProperty.GetValue(sessionItems, null);


            DebugInfo debugInfo = DebugInfoHelper.CreateDebugInfo(app.Context);

            app.Context.Items[ItemKey] = debugInfo;


            if (dirty == false)
            {
                // 还原状态,避免Session重新写入
                dirtyProperty.SetValue(sessionItems, false, null);
            }
        }
Esempio n. 2
0
        private void App_UpdateRequestCache(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            DebugInfo debugInfo = app.Context.Items[ItemKey] as DebugInfo;

            if (debugInfo == null)
            {
                return;
            }

            DebugInfoHelper.SetSize(debugInfo);

            DataQueue.Add(debugInfo);
        }