纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
1.1 KiB

3 years ago
  1. using NFine.Code;
  2. using System.Text;
  3. using System.Web.Mvc;
  4. namespace NFine.Web
  5. {
  6. public class HandlerErrorAttribute : HandleErrorAttribute
  7. {
  8. public override void OnException(ExceptionContext context)
  9. {
  10. base.OnException(context);
  11. context.ExceptionHandled = true;
  12. context.HttpContext.Response.StatusCode = 200;
  13. context.Result = new ContentResult { Content = new AjaxResult { state = ResultType.error.ToString(), message = context.Exception.Message }.ToJson() };
  14. //StringBuilder sbScript = new StringBuilder();
  15. //sbScript.Append("<script type='text/javascript'>alert('登录超时,请重新登录!');top.location.href = '/Login/Index';</script>");
  16. //context.Result = new ContentResult() { Content = sbScript.ToString() };
  17. }
  18. private void WriteLog(ExceptionContext context)
  19. {
  20. if (context == null)
  21. return;
  22. var log = LogFactory.GetLogger(context.Controller.ToString());
  23. log.Error(context.Exception);
  24. }
  25. }
  26. }