Exemplo n.º 1
0
        protected HttpResponseMessage CreateResponseMessage <T>(HttpBackCode code, T data, string message = null)
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            var back     = new HttpBackResult <T> {
                Status = (int)code, Msg = message == null?code.GetDescription() : message, Data = data
            };

            response.Content = new StringContent(back.ToJson());
            return(response);
        }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            bool   isValid = false;
            string token   = HttpContext.Current.Request["token"];

            //验证token是否有效
            //isValid=fun(token);

            if (!isValid)
            {
                var back = new HttpBackResult <object> {
                    Status = (int)HttpBackCode.UnAuthorized, Msg = "token验证未通过"
                };
                actionContext.Response.Content = new StringContent(back.ToJson());
            }
            else
            {
                base.OnAuthorization(actionContext);
            }
        }