/// <summary> /// Ons the begin request. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void onBeginRequest(object sender, EventArgs e) { if (processRequest()) { HttpResponse mResponse = HttpContext.Current.Response; m_Filter = new OutputFilterStream(mResponse.Filter); mResponse.Filter = m_Filter; } bool mStartLogInfo = false; if (HttpContext.Current.Application["StartLogInfo"] == null) { HttpContext.Current.Application["StartLogInfo"] = mStartLogInfo; } else { if (HttpContext.Current.Application["StartLogInfo"].ToString().ToUpperInvariant() == "FALSE") { mStartLogInfo = false; } else { mStartLogInfo = true; } } bool mClearedCache = true; if (HttpContext.Current.Application["ClearedCache"] == null) { HttpContext.Current.Application["ClearedCache"] = mClearedCache; } else { if (HttpContext.Current.Application["ClearedCache"].ToString().ToUpperInvariant() == "FALSE") { mClearedCache = false; } else { mClearedCache = true; } } if (!mStartLogInfo) { HttpContext.Current.Application["StartLogInfo"] = "True"; Logger mLog = Logger.Instance(); mLog.SetThreshold(LogPriority.Info); mLog.Info("Starting Core Web Administration Version: " + GWWebHelper.CoreWebAdministrationVersion); mLog.Info("Framework Version: " + GWWebHelper.FrameworkVersion); string mCurrentLevel = ConfigSettings.LogPriority.ToUpper(CultureInfo.InvariantCulture); mLog.SetThreshold(mLog.GetLogPriorityFromText(mCurrentLevel)); } }
/// <summary> /// Ons the end request. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> /// <exception cref="System.Exception"></exception> private void onEndRequest(Object sender, EventArgs e) { if (processRequest()) { MClientChoicesState mState = (MClientChoicesState)HttpContext.Current.Items[MClientChoices.SessionName]; //Save ClientChoicesState back to data store if (mState != null) { if (mState.IsDirty) { ClientChoicesUtility.Save(mState); } } HttpContext mContext = (sender as HttpApplication).Context; bool mSendError = false; try { if (mContext.Response.Headers["jsonerror"] != null) { string mError = string.Empty; if (m_Filter != null) { mError = m_Filter.ReadStream(); if (mContext.Response.Headers["jsonerror"].ToString().ToUpperInvariant().Trim() == "TRUE") { mSendError = true; formatError(ref mError); throw (new WebSupportException(String.Concat("An AJAX error has occurred: ", Environment.NewLine, mError))); } } else { if (mContext.Response.Headers["jsonerror"].ToString().ToUpperInvariant().Trim() == "TRUE") { mSendError = true; throw (new WebSupportException(String.Concat("An AJAX error has occurred: ", Environment.NewLine))); } } } } catch (WebSupportException ex) { if (mSendError) { if (!ex.ToString().Contains("Invalid JSON primitive")) { Logger mLog = Logger.Instance(); mLog.Error(ex); } if (mContext != null) { HttpResponse mCurrentResponse = mContext.Response; if (mCurrentResponse != null) { mCurrentResponse.Clear(); mCurrentResponse.Write("{\"Message\":\"We are very sorry but an error has occurred, please try your request again.\"}"); mCurrentResponse.ContentType = "text/html"; mCurrentResponse.StatusDescription = "500 Internal Error"; mCurrentResponse.StatusCode = 500; mCurrentResponse.TrySkipIisCustomErrors = true; mCurrentResponse.Flush(); HttpContext.Current.Server.ClearError(); HttpContext.Current.ApplicationInstance.CompleteRequest(); } } } } finally { if (m_Filter != null) { m_Filter.Dispose(); m_Filter = null; } } } }