Ejemplo n.º 1
0
 private void SetCurrentMethodInfoAndWrapResultAttribute(ActionExecutingContext filterContext)
 {
     _currentMethodInfo   = ActionDescriptorHelper.GetMethodInfo(filterContext.ActionDescriptor);
     _wrapResultAttribute =
         ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrNull <WrapResultAttribute>(_currentMethodInfo) ??
         WrapResultAttribute.Default;
 }
Ejemplo n.º 2
0
 public AbpAspNetCoreConfiguration()
 {
     DefaultWrapResultAttribute        = new WrapResultAttribute();
     DefaultUnitOfWorkAttribute        = new UnitOfWorkAttribute();
     ServiceControllerSettings         = new List <AbpServiceControllerSetting>();
     IsValidationEnabledForControllers = true;
 }
Ejemplo n.º 3
0
        protected virtual void HandleAndWrapException(PageHandlerExecutedContext context,
                                                      WrapResultAttribute wrapResultAttribute)
        {
            if (!ActionResultHelper.IsObjectResult(context.HandlerMethod.MethodInfo.ReturnType))
            {
                return;
            }

            var displayUrl = context.HttpContext.Request.GetDisplayUrl();

            if (_abpWebCommonModuleConfiguration.WrapResultFilters.HasFilterForWrapOnError(displayUrl,
                                                                                           out var wrapOnError))
            {
                context.HttpContext.Response.StatusCode = GetStatusCode(context, wrapOnError);

                if (!wrapOnError)
                {
                    return;
                }

                HandleError(context);
                return;
            }

            context.HttpContext.Response.StatusCode = GetStatusCode(context, wrapResultAttribute.WrapOnError);

            if (!wrapResultAttribute.WrapOnError)
            {
                return;
            }

            HandleError(context);
        }
        protected virtual void HandleAndWrapException(ExceptionContext context, WrapResultAttribute wrapResultAttribute)
        {
            if (!ActionResultHelper.IsObjectResult(context.ActionDescriptor.GetMethodInfo().ReturnType))
            {
                return;
            }

            context.HttpContext.Response.StatusCode = GetStatusCode(context, wrapResultAttribute.WrapOnError);

            if (!wrapResultAttribute.WrapOnError)
            {
                return;
            }

            context.Result = new ObjectResult(
                new AjaxResponse(
                    _errorInfoBuilder.BuildForException(context.Exception),
                    context.Exception is MajidAuthorizationException
                    )
                );

            EventBus.Trigger(this, new MajidHandledExceptionData(context.Exception));

            context.Exception = null; //Handled!
        }
Ejemplo n.º 5
0
 public AbpWebApiConfiguration()
 {
     HttpConfiguration                    = GlobalConfiguration.Configuration;
     DefaultUnitOfWorkAttribute           = new UnitOfWorkAttribute();
     DefaultWrapResultAttribute           = new WrapResultAttribute(false);
     DefaultDynamicApiWrapResultAttribute = new WrapResultAttribute();
 }
 public AbpMvcConfiguration()
 {
     DefaultUnitOfWorkAttribute              = new UnitOfWorkAttribute();
     DefaultWrapResultAttribute              = new WrapResultAttribute();
     IsValidationEnabledForControllers       = true;
     IsAutomaticAntiForgeryValidationEnabled = true;
 }
 public AbpWebApiConfiguration()
 {
     HttpConfiguration                    = GlobalConfiguration.Configuration;
     DefaultUnitOfWorkAttribute           = new UnitOfWorkAttribute();
     DefaultWrapResultAttribute           = new WrapResultAttribute(false);
     DefaultDynamicApiWrapResultAttribute = new WrapResultAttribute();
     IsValidationEnabledForControllers    = true;
 }
 public AbpAspNetCoreConfiguration()
 {
     DefaultWrapResultAttribute        = new WrapResultAttribute();
     DefaultUnitOfWorkAttribute        = new UnitOfWorkAttribute();
     ControllerAssemblySettings        = new ControllerAssemblySettingList();
     FormBodyBindingIgnoredTypes       = new List <Type>();
     IsValidationEnabledForControllers = true;
     SetNoCacheForAjaxResponses        = true;
     IsAuditingEnabled = true;
 }
Ejemplo n.º 9
0
 public AbpWebApiConfiguration()
 {
     HttpConfiguration                       = GlobalConfiguration.Configuration;
     DefaultUnitOfWorkAttribute              = new UnitOfWorkAttribute();
     DefaultWrapResultAttribute              = new WrapResultAttribute(false);
     DefaultDynamicApiWrapResultAttribute    = new WrapResultAttribute();
     ResultWrappingIgnoreUrls                = new List <string>();
     IsValidationEnabledForControllers       = true;
     IsAutomaticAntiForgeryValidationEnabled = true;
     SetNoCacheForAllResponses               = true;
 }
Ejemplo n.º 10
0
        public void OnResultExecuting(ResultExecutingContext context)
        {
            if (!context.ActionDescriptor.IsControllerAction())
            {
                return;
            }

            var defaultValue        = new WrapResultAttribute(_configuration.GetValue <bool>("WrapResultDefault"));
            var methodInfo          = context.ActionDescriptor.GetMethodInfo();
            var wrapResultAttribute = ReflectionHelper.GetAttributeOrDefault(methodInfo, defaultValue);

            if (!wrapResultAttribute.IsWrap)
            {
                return;
            }

            if (context.Result is ObjectResult)
            {
                var objectResult = context.Result as ObjectResult;
                if (objectResult == null)
                {
                    throw new ArgumentException($"{nameof(context.Result)} should be ObjectResult!");
                }

                if (!(objectResult.Value is Result))
                {
                    objectResult.Value = new Result((int)ResultCodeEnum.Success)
                    {
                        Data = objectResult.Value
                    };
                }
            }
            else if (context.Result is JsonResult)
            {
                var jsonResult = context.Result as JsonResult;
                if (jsonResult == null)
                {
                    throw new ArgumentException($"{nameof(context.Result)} should be JsonResult!");
                }

                jsonResult.Value = new Result((int)ResultCodeEnum.Success)
                {
                    Data = jsonResult.Value
                };
            }
            else if (context.Result is EmptyResult)
            {
                context.Result = new ObjectResult(new Result((int)ResultCodeEnum.Success));
            }
            else
            {
                // Null
            }
        }
Ejemplo n.º 11
0
 public CodeZeroAspNetCoreConfiguration()
 {
     DefaultWrapResultAttribute        = new WrapResultAttribute();
     DefaultClientCacheAttribute       = new NoClientCacheAttribute(false);
     DefaultUnitOfWorkAttribute        = new UnitOfWorkAttribute();
     ControllerAssemblySettings        = new ControllerAssemblySettingList();
     FormBodyBindingIgnoredTypes       = new List <Type>();
     RouteConfiguration                = new List <Action <IRouteBuilder> >();
     IsValidationEnabledForControllers = true;
     SetNoCacheForAjaxResponses        = true;
     IsAuditingEnabled = true;
 }
Ejemplo n.º 12
0
 public AbpAspNetCoreConfiguration()
 {
     DefaultWrapResultAttribute        = new WrapResultAttribute();
     DefaultClientCacheAttribute       = new NoClientCacheAttribute(false);
     DefaultUnitOfWorkAttribute        = new UnitOfWorkAttribute();
     ControllerAssemblySettings        = new ControllerAssemblySettingList();
     FormBodyBindingIgnoredTypes       = new List <Type>();
     EndpointConfiguration             = new List <Action <IEndpointRouteBuilder> >();
     IsValidationEnabledForControllers = true;
     SetNoCacheForAjaxResponses        = true;
     IsAuditingEnabled = true;
     UseMvcDateTimeFormatForAppServices = false;
 }
Ejemplo n.º 13
0
        private void SetCurrentMethodInfoAndWrapResultAttribute(ActionExecutingContext filterContext)
        {
            //Prevent overriding for child actions
            if (_currentMethodInfo != null)
            {
                return;
            }

            _currentMethodInfo   = filterContext.ActionDescriptor.GetMethodInfoOrNull();
            _wrapResultAttribute =
                ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(
                    _currentMethodInfo,
                    AbpMvcConfiguration.DefaultWrapResultAttribute
                    );
        }
Ejemplo n.º 14
0
        // 处理并包装异常
        protected virtual void HandleAndWrapException(ExceptionContext context, WrapResultAttribute wrapResultAttribute)
        {
            if (!ActionResultHelper.IsObjectResult(context.ActionDescriptor.GetMethodInfo().ReturnType))
            {
                return;
            }

            //var displayUrl = context.HttpContext.Request.GetDisplayUrl();
            //if (_abpWebCommonModuleConfiguration.WrapResultFilters.HasFilterForWrapOnError(displayUrl,
            //    out var wrapOnError))
            //{
            //    context.HttpContext.Response.StatusCode = GetStatusCode(context, wrapOnError);

            //    if (!wrapOnError)
            //    {
            //        return;
            //    }

            //    HandleError(context);
            //    return;
            //}

            //context.HttpContext.Response.StatusCode = GetStatusCode(context, wrapResultAttribute.WrapOnError);

            //if (!wrapResultAttribute.WrapOnError)
            //{
            //    return;
            //}

            //HandleError(context);

            context.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK;
            var errorInfo = _errorInfoBuilder.BuildForException(context.Exception);

            errorInfo.Message = context.Exception.Message;
            errorInfo.Code    = GetStatusCode(context, errorInfo);
            context.Result    = new ObjectResult(
                new AjaxResponse(
                    errorInfo,
                    context.Exception is AbpAuthorizationException
                    )
                );

            EventBus.Trigger(this, new AbpHandledExceptionData(context.Exception));

            context.Exception = null; //Handled!
        }
Ejemplo n.º 15
0
 public AbpMvcConfiguration()
 {
     DefaultUnitOfWorkAttribute = new UnitOfWorkAttribute();
     DefaultWrapResultAttribute = new WrapResultAttribute();
 }
Ejemplo n.º 16
0
 public RivenAspNetCoreOptions()
 {
     _defaultWrapResultAttribute = new WrapResultAttribute();
 }