.net MVC 如何从全局拦截程序执行异常错误
新建 BaseController 继承 Controller
新建方法 GetParamsFromRequest 获取上下文字符串
/// <summary>
/// 通过ExceptionContext获取参数上下文
/// </summary>
/// <param name="filterContext"></param>
private string GetParamsFromRequest(ExceptionContext filterContext)
{
StringBuilder sb = new StringBuilder();
if (filterContext.HttpContext.Request.InputStream.Length > 0)
{
byte[] byts = new byte[filterContext.HttpContext.Request.InputStream.Length];
filterContext.HttpContext.Request.InputStream.Position = 0;
filterContext.HttpContext.Request.InputStream.Read(byts, 0, byts.Length);
sb.Append("------------------InputStream(Json Post)------------------<br>");
sb.Append(HttpUtility.UrlDecode(System.Text.Encoding.Default.GetString(byts))+ "<br>");
sb.Append("------------------InputStream(Json Post)