zoukankan      html  css  js  c++  java
  • MVC Json输出调试信息


    当测试环境、生产环境不能够调试的时候,有的时候想通过一些参数跟踪出想要的数据。如:SOA,DALSQL 等。

     
    public class DebugJsonResult: JsonResult
        {
            public DebugJsonResult(object Data)
            {
                base.Data = Data;
            }
    
            public override void ExecuteResult(ControllerContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }
    
                HttpResponseBase response = context.HttpContext.Response;
    
                if (!string.IsNullOrEmpty(ContentType))
                    response.ContentType = ContentType;
                else
                    response.ContentType = "application/json";
    
                if (ContentEncoding != null)
                    response.ContentEncoding = ContentEncoding;
                
                if (Data != null)
                {
                    string jsonData = JsonNetHelper.ToJson(Data);
                    if (ControllerDebug.GetInstance.IsDebug == true)
                    {
                        try
                        {
                            if (jsonData.LastIndexOf("}") + 1 == jsonData.Length)
                            {
                                DebugInfoResult debuginfo = new DebugInfoResult();
                                debuginfo.DebugInfo = ControllerDebug.GetInstance.DebugList;
    
                                string strdebuginfo = jsonData.Insert(jsonData.LastIndexOf("}"), "," + JsonNetHelper.ToJson(ControllerDebug.GetInstance.DebugList));
                                response.Write(strdebuginfo);
                            }
                            else
                            {
                                response.Write(jsonData);
                            }
                        }
                        catch
                        {
                            
                            response.Write(jsonData);
                        }
                    }
                    else
                    {
                         
                        response.Write(jsonData);
                    }
                }
            }
        }
    
        public class DebugInfoResult 
        {
            /// <summary>
            /// Debug 信息
            /// </summary>
            public object DebugInfo
            {
                get;
                set;
            }
        }

     
    在 调用Controller 是传入isdebug 参数.

    public class IoCControllerFactory : DefaultControllerFactory
    {
    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
            {
    if (HttpContext.Current.Request.QueryString["isdebug"]!=null)
                {
                    string sisdebug = HttpContext.Current.Request.QueryString["isdebug"].ToString().ToUpper();
    
                    if (sisdebug.IndexOf("T") >= 0)
                    {
                        string tempisdebug = sisdebug.Replace("T","").Replace("-","");
    
                        if (!string.IsNullOrEmpty(tempisdebug))
                        { 
                             ControllerDebug.GetInstance.SearchType= (EnumDebug)Enum.Parse(typeof(EnumDebug), tempisdebug.ToUpper());
                        }
    
                        //开启调试.
                        ControllerDebug.GetInstance.IsDebug = true;
                        ControllerDebug.GetInstance.DebugList.Clear();
                    }
                    else
                    {
                        ControllerDebug.GetInstance.IsDebug = false;
                        ControllerDebug.GetInstance.DebugList.Clear();
                    }
                }
                else
                {
                    ControllerDebug.GetInstance.IsDebug = false;
                    ControllerDebug.GetInstance.DebugList.Clear();
                }
    return base.GetControllerInstance(requestContext, controllerType);
         }
    }
    public abstract class BaseController : System.Web.Mvc.Controller
        {
    protected override JsonResult Json(object data, string contentType, Encoding contentEncoding)
            {
                return new DebugJsonResult(data);
            }
         }
    public class BookingGroupOrderController : BaseController
        {
        [HttpPost]
            public ActionResult CreateOrder(O_BookingCreateOrder obj)
            {
                IOrderBiz GOBiz = Ioc.IoCFactory.Instance.CurrentContainer.Resolve<IOrderBiz>("BookingGroupOrder");
    
                ICreateOrder createobject = GOBiz.CreateOrder<O_BookingCreateOrder>(obj);
    
                return Json(createobject, null, null);
            }
    }


    Q[`8A4X9LR%8GA8B~@_LY)I

  • 相关阅读:
    【sqli-labs】 less37 POST- Bypass MYSQL_real_escape_string (POST型绕过MYSQL_real_escape_string的注入)
    【sqli-labs】 less36 GET- Bypass MYSQL_real_escape_string (GET型绕过MYSQL_real_escape_string的注入)
    【sqli-labs】 less35 GET- Bypass Add Slashes(we dont need them) Integer based (GET型绕过addslashes() 函数的整型注入)
    【sqli-labs】 less34 POST- Bypass AddSlashes (POST型绕过addslashes() 函数的宽字节注入)
    【sqli-labs】 less33 GET- Bypass AddSlashes (GET型绕过addslashes() 函数的宽字节注入)
    【sqli-labs】 less31 GET- Blind -Impidence mismatch -Having a WAF in front of web application (GET型基于盲注的带有WAF注入)
    iptables(3)
    iptables(2)
    iptables(1)
    rsync服务部署
  • 原文地址:https://www.cnblogs.com/kfsmqoo/p/4551530.html
Copyright © 2011-2022 走看看