ASP.NET MVC ApiController過濾器處理返回結果

    public class OpenIdAutoDecryptAttr : ActionFilterAttribute
    {
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            base.OnActionExecuted(actionExecutedContext);
            var objectContent = actionExecutedContext.Response.Content as ObjectContent;
            if (objectContent != null && objectContent.Value != null && (objectContent.Value.GetType().BaseType == typeof(Parm) || objectContent.Value.GetType() == typeof(Parm)))
            {
                Parm parm = (Parm)objectContent.Value;
                if (!String.IsNullOrEmpty(parm.ErrMsg))
                {
                    LogUtil.DoLog("ErrMsg Before", parm.ErrMsg);
                    Regex regex = new Regex(@"(ORA-[0-9]{1,}:)(.*)\r\n(.*)");
                    if (regex.IsMatch(parm.ErrMsg))
                    {
                        parm.ErrMsg = regex.Match(parm.ErrMsg).Result("$2").Trim();
                    }
                    LogUtil.DoLog("ErrMsg After", parm.ErrMsg);
                }
            }
        }
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章