/// <inheritdoc />
 public void ReleaseController(System.Web.Mvc.IController controller)
 {
     throw new NotImplementedException();
 }
Esempio n. 2
0
        /// <summary>
        /// Executes the GStore controller with an error view. controller must be set
        /// </summary>
        /// <param name="errorPage"></param>
        /// <param name="httpStatusCode"></param>
        /// <param name="ex"></param>
        /// <param name="clearError"></param>
        /// <param name="context"></param>
        /// <param name="controller"></param>
        /// <returns></returns>
        public static bool TryExecuteAppErrorController(ErrorPage errorPage, int httpStatusCode, Exception ex, bool clearError, HttpContext context, BaseController controller)
        {
            string url    = string.Empty;
            string rawUrl = string.Empty;

            if (context != null)
            {
                url    = context.Request.Url.ToString();
                rawUrl = context.Request.RawUrl;
            }

            if (controller == null)
            {
                System.Diagnostics.Trace.WriteLine("--Failure. Controller is null; no error controller is available ErrorPage: " + errorPage.ToString() + " Url: " + url + " RawUrl: " + rawUrl + " Original Exception: " + ex.Message);
                return(false);
            }

            var routeData = new RouteData();

            //if we can find the current area from the url, we can use a area-specific error handler to incorporate area layout/design
            string area = context.Request.DetermineAreaFromRequest();

            if (!string.IsNullOrEmpty(area))
            {
                routeData.DataTokens.Add("area", area);
            }
            routeData.Values["controller"]     = "GStore";
            routeData.Values["action"]         = "AppError";
            routeData.Values["exception"]      = ex;
            routeData.Values["errorpage"]      = errorPage;
            routeData.Values["httpStatusCode"] = httpStatusCode;

            System.Web.Mvc.IController errorController = null;
            if (controller != null)
            {
                try
                {
                    errorController = controller.GStoreErrorControllerForArea;
                }
                catch (Exception exAreaError)
                {
                    System.Diagnostics.Trace.WriteLine("--Failure. Error getting GStoreErrorControllerForArea for ErrorPage: " + errorPage.ToString() + " Url: " + url + " RawUrl: " + rawUrl + " Exception: " + exAreaError.Message + " Original Exception: " + ex.Message);
                    return(false);
                }
            }

            var rc = new RequestContext(new HttpContextWrapper(context), routeData);

            try
            {
                System.Diagnostics.Trace.WriteLine("--Executing error controller for ErrorPage: " + errorPage.ToString() + " Url: " + url + " RawUrl: " + rawUrl + " Original Exception: " + ex.Message);
                errorController.Execute(rc);
                System.Diagnostics.Trace.WriteLine("--Success executing error controller for ErrorPage: " + errorPage.ToString() + " Url: " + url + " RawUrl: " + rawUrl + " Original Exception: " + ex.Message);
                if (clearError)
                {
                    context.ClearError();
                }
                return(true);
            }
            catch (Exception exErrorController)
            {
                System.Diagnostics.Trace.WriteLine("--Failure. Error executing error controller for ErrorPage: " + errorPage.ToString() + " Url: " + url + " RawUrl: " + rawUrl + " Exception: " + exErrorController.Message + " Original Exception: " + ex.Message);
                return(false);
            }
        }