/// <summary> /// 系统授权接口 /// </summary> //private IAuthenticationManager AuthenticationManager //{ // get // { // return HttpContext.GetOwinContext().Authentication; // } //} //private void Authorization() //{ // string username=Request.QueryString["username"]; // if (string.IsNullOrEmpty(username)) // return; // var _identity = CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); // AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); // AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = vm.IsRember, }, _identity); // } #region 发生异常、错误信息 protected override void OnException(ExceptionContext filterContext) { RpsData rqd = new RpsData(); rqd.IsSucceed = false; rqd.ErrorCode = 200; if (filterContext.Exception.InnerException != null && filterContext.Exception is CustomException) { CustomException ex = filterContext.Exception.InnerException as CustomException; rqd = RpsData.Fail(ex.Code, ex.Message); } else { rqd = RpsData.Fail(filterContext.Exception.Message); //Log.Write(filterContext.Exception); LogHelper.Write(filterContext.Exception); } rqd.Error = filterContext.Exception.Message; filterContext.HttpContext.Response.Clear(); filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.StatusCode = 200; filterContext.HttpContext.Response.Write(JsonExtend.ToJson(rqd)); filterContext.HttpContext.Response.Flush(); filterContext.HttpContext.Response.End(); }
public override void ExecuteResult(ControllerContext context) { if (context == null) { throw new ArgumentException("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) { //JavaScriptSerializer serializer = new JavaScriptSerializer(); //response.Write(serializer.Serialize(Data)); RpsData rqsdata = new RpsData(); string jsonstr = ""; if (Data.GetType().Name == "DataTable") { rqsdata = RpsData.Succee((Data as DataTable).ToJArray()); jsonstr = JsonExtend.ToJson(rqsdata); } //jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject((Data as DataTable).ToJArray()); else if (Data.GetType().Name == "DataRow") { rqsdata = RpsData.Succee((Data as DataRow).ToJObject()); jsonstr = JsonExtend.ToJson(rqsdata); } //jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject((Data as DataRow).ToJObject()); else { rqsdata = RpsData.Succee(Data); jsonstr = JsonExtend.ToKonwnTypeJson(rqsdata); } //jsonstr = Newtonsoft.Json.JsonConvert.SerializeObject(Data); response.Write(jsonstr); } else { response.Write(JsonExtend.ToKonwnTypeJson(RpsData.Succee(null))); } }