纽威
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.

28 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. //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. context.Result = new ContentResult() { Content = sbScript.ToString() };
  18. }
  19. private void WriteLog(ExceptionContext context)
  20. {
  21. if (context == null)
  22. return;
  23. var log = LogFactory.GetLogger(context.Controller.ToString());
  24. log.Error(context.Exception);
  25. }
  26. }
  27. }