示例#1
0
        /// <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();
        }