private void SetCurrentMethodInfoAndWrapResultAttribute(ActionExecutingContext filterContext) { _currentMethodInfo = ActionDescriptorHelper.GetMethodInfo(filterContext.ActionDescriptor); _wrapResultAttribute = ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrNull <WrapResultAttribute>(_currentMethodInfo) ?? WrapResultAttribute.Default; }
public AbpAspNetCoreConfiguration() { DefaultWrapResultAttribute = new WrapResultAttribute(); DefaultUnitOfWorkAttribute = new UnitOfWorkAttribute(); ServiceControllerSettings = new List <AbpServiceControllerSetting>(); IsValidationEnabledForControllers = true; }
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! }
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; }
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; }
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 } }
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; }
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; }
private void SetCurrentMethodInfoAndWrapResultAttribute(ActionExecutingContext filterContext) { //Prevent overriding for child actions if (_currentMethodInfo != null) { return; } _currentMethodInfo = filterContext.ActionDescriptor.GetMethodInfoOrNull(); _wrapResultAttribute = ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault( _currentMethodInfo, AbpMvcConfiguration.DefaultWrapResultAttribute ); }
// 处理并包装异常 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! }
public AbpMvcConfiguration() { DefaultUnitOfWorkAttribute = new UnitOfWorkAttribute(); DefaultWrapResultAttribute = new WrapResultAttribute(); }
public RivenAspNetCoreOptions() { _defaultWrapResultAttribute = new WrapResultAttribute(); }