QSMP.Web/Filters/ErrorCheckedAttribute.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using QSMP.Utility.Operator;
using QSMP.Utility.Log;
using QSMP.Logic.Sys;

namespace QSMP.Web.Filters
{
    /// <summary>
    /// 表示一个特性,该特性用于捕获程序运行异常。
    /// </summary>
    public class ErrorCheckedAttribute : HandleErrorAttribute
    {
        public override void OnException(ExceptionContext filterContext)
        {
            filterContext.HttpContext.Response.StatusCode = 500;
            filterContext.ExceptionHandled = true;
            StringBuilder script = new StringBuilder();

            LogHelper.Error(filterContext.Exception.StackTrace);

            if (OperatorProvider.Instance.Current == null)
            {
                script.Append("<script>top.alert('登陆超时,请重新认证。'); top.window.location.href='/Account/Login'</script>");
                filterContext.Result = new ContentResult() { Content = script.ToString() };
            }
            else
            {
                Operator onlineUser = OperatorProvider.Instance.Current;
                LogHelper.Write(Level.Error, "程序抛异常", filterContext.Exception.StackTrace, onlineUser.Account, onlineUser.RealName);
                new LogLogic().Write(Level.Error, "程序抛异常", filterContext.Exception.StackTrace, onlineUser.Account, onlineUser.RealName);
                script.Append("<script>top.window.alert('系统出现异常,请联系开发人员确认。');</script>");
                filterContext.Result = new ContentResult() { Content = script.ToString() };
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。