示例#1
0
        protected void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs

            // Get the exception object.
            Exception exc = Server.GetLastError();

            if (Context.Request.IsApiRequest() || Context.Request.IsAjaxRequest())
            {
                Context.ClearError();

                Context.Response.TrySkipIisCustomErrors = true;
                if (exc is HttpException)
                {
                    Context.Response.StatusCode = (exc as HttpException).GetHttpCode();
                    Context.Response.SuppressFormsAuthenticationRedirect = true;
                }
                else
                {
                    Context.Response.StatusCode = (int)HttpStatusCode.OK;
                }

                Context.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(Context.Response.StatusCode);

                var jsonResponse = new ChalkableJsonResponce(ExceptionViewData.Create(exc))
                {
                    Success = false
                };

                var serializer = new MagicJsonSerializer(true)
                {
                    MaxDepth = 4
                };
                var result = serializer.Serialize(jsonResponse);

                Context.Response.ContentType = "application/json";
                Context.Response.Write(result);

                return;
            }

            // Handle HTTP errors
            if (exc is HttpException)
            {
                // The Complete Error Handling Example generates
                // some errors using URLs with "NoCatch" in them;
                // ignore these here to simulate what would happen
                // if a global.asax handler were not implemented.
                if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
                {
                    // ReSharper disable once RedundantJumpStatement
                    return;
                }
            }

#if !DEBUG
            RaygunClient.SendInBackground(exc);
#endif
        }
示例#2
0
        protected void PrepareJsonData(object data, string name, int maxDepth = 4)
        {
            var jsonResponse = new ChalkableJsonResponce(data);
            var serializer   = new MagicJsonSerializer(false)
            {
                MaxDepth = maxDepth
            };
            var res = serializer.Serialize(jsonResponse);

            ViewData[name] = res;
        }
示例#3
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            HttpResponseBase response = context.HttpContext.Response;

            response.ContentType = ContentType;
            if (Data != null)
            {
                var serializer = new MagicJsonSerializer(hideSensitive);
                serializer.MaxDepth = SerializationDepth;
                string result = serializer.Serialize(Data);
                response.Write(result);
            }
        }