示例#1
0
        /// <summary>
        /// 授权失败处理
        /// </summary>
        /// <param name="actionContext"></param>
        /// <param name="vret">返回消息</param>
        private Task HandleUnauthorizedRequest(HttpActionContext actionContext, Result vret)
        {
            HttpResponseMessage response = new HttpResponseMessage();
            Result res = new Result(vret.Message, vret.Success);

            res.Status = vret.Status;

            response.Content       = new StringContent(JsonExtention.ToJsonString(res), Encoding.GetEncoding("UTF-8"), "application/json");
            response.StatusCode    = HttpStatusCode.OK;
            actionContext.Response = response;

            //授权失败,收集访问信息
            VisitorTerminal vt = AL.Common.Extention.WebExtention.GetVisitorTerminal();

            LogHelper.Info(vt);//存储
            return(Task.FromResult <object>(null));
        }
示例#2
0
        public override Task OnExceptionAsync(HttpActionExecutedContext context, CancellationToken cancellationToken)
        {
            dynamic reqMessage = new
            {
                Success = false,
                Status  = 500,
                Message = "系统繁忙"
            };
            string msg = JsonExtention.ToJsonString(reqMessage);
            HttpResponseMessage response = new HttpResponseMessage();

            response.Content    = new StringContent(msg, Encoding.GetEncoding("UTF-8"), "application/json");
            response.StatusCode = HttpStatusCode.OK;
            context.Response    = response;

            //文本日志记录
            LogHelper.Error(context.Exception.Message, "", context.Exception);

            return(Task.FromResult <object>(null));
        }
示例#3
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.Exception == null)
            {
                //获取方法上下文
                string controller = filterContext.RouteData.Values["controller"].ToString();
                string action     = filterContext.RouteData.Values["action"].ToString();
                object area       = filterContext.RouteData.Values["area"];
                //返回消息
                string message = filterContext.Controller.ViewBag.Message;

                //获取请求Form和QueryString参数
                NameValueCollection formcoll  = filterContext.Controller.ControllerContext.HttpContext.Request.Form;
                NameValueCollection querycoll = filterContext.Controller.ControllerContext.HttpContext.Request.QueryString;


                StringBuilder builder = new StringBuilder();
                if (!string.IsNullOrEmpty(this.ParameterNameList))
                {
                    //记录设置的参数
                    foreach (string key in this.ParameterNameList.Split(new char[] { ',', '|' }))
                    {
                        string value = formcoll[key];
                        if (string.IsNullOrEmpty(value))
                        {
                            value = querycoll[key];
                        }
                        if (!string.IsNullOrEmpty(value))
                        {
                            builder.AppendFormat("{0}={1}&", key, value);
                        }
                    }
                }
                else
                {
                    //未设置记录参数,就默认记录全部Form和QueryString参数
                    foreach (string key in formcoll.Keys)
                    {
                        builder.AppendFormat("{0}={1}&", key, formcoll[key]);
                    }
                    foreach (string key in querycoll.Keys)
                    {
                        builder.AppendFormat("{0}={1}&", key, querycoll[key]);
                    }
                }

                if (string.IsNullOrEmpty(message))
                {
                    message = "";
                }
                if (string.IsNullOrEmpty(this.Message))
                {
                    this.Message = "";
                }
                dynamic log = new
                {
                    action_name     = action,                                                           //请求方法
                    controller_name = area + "/" + controller,                                          //请求控制器
                    action_data     = builder.ToString(),                                               //请求参数
                    action_ip       = filterContext.RequestContext.HttpContext.Request.UserHostAddress, //请求客户端IP
                    action_time     = DateTime.Now,
                    action_title    = this.Message,
                    remark          = message,
                    user_id         = (filterContext.Controller is BaseOAuthController)? (filterContext.Controller as BaseOAuthController).UserId:0
                };

                //记录日志
                message = JsonExtention.ToJsonString(log);
                LogHelper.Info(message);

                base.OnActionExecuted(filterContext);
            }
        }
示例#4
0
 /// <summary>
 /// 结果对象转换为String
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static string ToJsonString(this Result source)
 {
     return(JsonExtention.ToJsonIgnoreNullString(source));
 }
示例#5
0
 public T ConvertObj <T>(RedisValue value)
 {
     return(JsonExtention.ToFromJson <T>(value));
 }
示例#6
0
        public string ConvertJson <T>(T value)
        {
            string result = value is string?value.ToString() : JsonExtention.ToJsonString(value);

            return(result);
        }