Ejemplo n.º 1
0
        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (context == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            //访问记录
            var visit = RequestHelper.Visit();

            VisitQueueInstance.Add(visit);

            var inWriteList = IPHelper.InWriteList(RequestHelper.GetClientIp());

            if (!inWriteList)
            {
                context.Result = new RedirectResult("/404.html");
            }
            //允许AllowAnonymous匿名访问
            var controllerActionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;

            if (controllerActionDescriptor != null)
            {
                var isDefined = controllerActionDescriptor.ControllerTypeInfo.GetCustomAttributes(inherit: true)
                                .Any(a => a.GetType().Equals(typeof(AllowAnonymousAttribute)));

                if (isDefined)
                {
                }
            }


            await base.OnActionExecutionAsync(context, next);
        }
Ejemplo n.º 2
0
        public ActionResult GetIp()
        {
            string ip = RequestHelper.GetClientIp();

            return(Content(ip));
        }