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.

29 lines
1.2 KiB

  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. //cookie时
  14. // context.Result = new ContentResult { Content = new AjaxResult { state = ResultType.error.ToString(), message = context.Exception.Message }.ToJson() };
  15. StringBuilder sbScript = new StringBuilder();
  16. sbScript.Append("<script type='text/javascript'>alert('登录超时,请重新登录!(" + context.Exception.Message + ")');</script>");
  17. //sbScript.Append("<script type='text/javascript'>alert('登录超时,请重新登录!');top.location.href = '/Login/Index';</script>");
  18. context.Result = new ContentResult() { Content = sbScript.ToString() };
  19. }
  20. private void WriteLog(ExceptionContext context)
  21. {
  22. if (context == null)
  23. return;
  24. var log = LogFactory.GetLogger(context.Controller.ToString());
  25. log.Error(context.Exception);
  26. }
  27. }
  28. }