예제 #1
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var descriptor          = (Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor;
            var attributeController = (IgnoreSignAttribute)descriptor.ControllerTypeInfo.GetCustomAttributes(typeof(IgnoreSignAttribute), true).FirstOrDefault();

            if (attributeController != null)
            {
                goto gotoNext;
            }

            var attribute = (IgnoreSignAttribute)descriptor.MethodInfo.GetCustomAttributes(typeof(IgnoreSignAttribute), true).FirstOrDefault();

            if (attribute != null)
            {
                goto gotoNext;
            }

            if (!GetSignValue(context.HttpContext.Request))
            {
                SignCommon.BuildErrorJson(context);
                return;
            }
            else
            {
                goto gotoNext;
            }

gotoNext:
            base.OnActionExecuting(context);
        }
예제 #2
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            IServiceProvider serviceProvider = context.HttpContext.RequestServices;
            var _logger           = serviceProvider.GetRequiredService <ILogger <VerifySignAttribute> >();
            var _configuration    = serviceProvider.GetRequiredService <IConfiguration>();
            var _verifySignCommon = serviceProvider.GetService <IOperationFilter>();
            var _verifySignOption = serviceProvider.GetService <VerifySignOption>();

            if (!_verifySignOption?.Enabled ?? true)
            {
                goto gotoNext;
            }

            var descriptor          = (Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor;
            var attributeController = (IgnoreSignAttribute)descriptor.ControllerTypeInfo.GetCustomAttributes(typeof(IgnoreSignAttribute), true).FirstOrDefault();

            if (attributeController != null)
            {
                goto gotoNext;
            }

            var attribute = (IgnoreSignAttribute)descriptor.MethodInfo.GetCustomAttributes(typeof(IgnoreSignAttribute), true).FirstOrDefault();

            if (attribute != null)
            {
                goto gotoNext;
            }

            var result = await GetSignValue(context.HttpContext, _logger, _verifySignOption, _verifySignCommon);

            if (_verifySignOption.IsForce && !result.Item1)
            {
                SignCommon.BuildErrorJson(context);
                await Task.CompletedTask;
                return;
            }
            else
            {
                goto gotoNext;
            }

gotoNext:
            await next();
        }