/// <summary>
        /// Returns an error response to the client from a callback. Code
        /// should exit after this call.
        /// </summary>
        /// <param name="ErrorMessage"></param>
        public void WriteErrorResponse(string errorMessage, string stackTrace, int statusCode = 500)
        {
            CallbackErrorResponseMessage Error = new CallbackErrorResponseMessage(errorMessage);

            Error.detail     = stackTrace;
            Error.statusCode = statusCode;

            JSONSerializer Serializer = new JSONSerializer();
            string         result     = null;

            SerializationUtils.SerializeObject(Error, out result);

            HttpResponse Response = HttpContext.Current.Response;

            Response.ContentType = WebResources.STR_XmlContentType;

            Response.TrySkipIisCustomErrors = true;

            if (Response.StatusCode == 200)
            {
                Response.StatusCode = statusCode;
            }

            Response.Write(result);
            //HttpContext.Current.ApplicationInstance.CompleteRequest();
            Response.End();
        }
Exemple #2
0
        /// <summary>
        /// Returns an error response to the client from a callback. Code
        /// should exit after this call.
        /// </summary>
        /// <param name="ErrorMessage"></param>
        public void WriteErrorResponse(string errorMessage, string stackTrace, int statusCode = 500)
        {
            CallbackErrorResponseMessage Error = new CallbackErrorResponseMessage(errorMessage);

            Error.detail     = stackTrace;
            Error.statusCode = statusCode;

            JSONSerializer Serializer = new JSONSerializer(SupportedJsonParserTypes.JavaScriptSerializer);
            string         result     = Serializer.Serialize(Error);

            if (!string.IsNullOrEmpty(JsonPMethod))
            {
                result = JsonPMethod + "( " + result + " );";
            }

            HttpResponse Response = HttpContext.Current.Response;

            Response.ContentType = WebResources.STR_JsonContentType;

            Response.TrySkipIisCustomErrors = true;

            // override status code but only if it wasn't set already
            if (Response.StatusCode == 200)
            {
                Response.StatusCode = statusCode;
            }

            Response.Write(result);
            Response.End();
        }
        public override void OnException(ExceptionContext filterContext)
        {            
            var response = filterContext.HttpContext.Response;
            
            // in allow debug mode just show standard ASP.NET error
            if (ShowErrorPageInDebugMode && filterContext.HttpContext.IsDebuggingEnabled)
            {
                base.OnException(filterContext);
                return;
            }

            var ex = filterContext.Exception.GetBaseException();            

            CallbackErrorResponseMessage resultMessage = new CallbackErrorResponseMessage(ex,AllowExceptionDetail);
            
            response.ContentType = "application/json";
            response.StatusCode = 500;
            var cbEx = ex as CallbackException;
        
            if (cbEx != null && cbEx.StatusCode > 0)
                response.StatusCode = ((CallbackException) ex).StatusCode;

            response.Write(JsonConvert.SerializeObject(resultMessage));
            
            filterContext.ExceptionHandled = true;            
            response.TrySkipIisCustomErrors = true;
        }
        /// <summary>
        /// Returns an error response to the client from a callback. Code
        /// should exit after this call.
        /// </summary>
        /// <param name="ErrorMessage"></param>
        public void WriteErrorResponse(string errorMessage, string stackTrace, int statusCode = 500)
        {
            CallbackErrorResponseMessage Error = new CallbackErrorResponseMessage(errorMessage);
            Error.detail = stackTrace;
            Error.statusCode = statusCode;

            JSONSerializer Serializer = new JSONSerializer( SupportedJsonParserTypes.JavaScriptSerializer);            
            string result = Serializer.Serialize(Error);

            if (!string.IsNullOrEmpty(JsonPMethod))
                result = JsonPMethod + "( " + result + " );";

            HttpResponse Response = HttpContext.Current.Response;
            Response.ContentType = WebResources.STR_JsonContentType;

            Response.TrySkipIisCustomErrors = true;
            
            // override status code but only if it wasn't set already
            if (Response.StatusCode == 200)
                Response.StatusCode = statusCode;
            
            Response.Write(result);            
            Response.End();
        }
        /// <summary>
        /// Returns an error response to the client from a callback. Code
        /// should exit after this call.
        /// </summary>
        /// <param name="ErrorMessage"></param>
        public void WriteErrorResponse(string errorMessage, string stackTrace, int statusCode = 500)
        {
            CallbackErrorResponseMessage Error = new CallbackErrorResponseMessage(errorMessage);            
            Error.detail = stackTrace;
            Error.statusCode = statusCode;
            
            JSONSerializer Serializer = new JSONSerializer();
            string result = null;
            SerializationUtils.SerializeObject(Error, out result);

            HttpResponse Response = HttpContext.Current.Response;
            Response.ContentType = WebResources.STR_XmlContentType;

            Response.TrySkipIisCustomErrors = true;
            
            if (Response.StatusCode == 200)
                Response.StatusCode = statusCode;

            Response.Write(result);
            //HttpContext.Current.ApplicationInstance.CompleteRequest();
            Response.End();
        }