public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            if (!string.IsNullOrWhiteSpace(ForHandler))
            {
                if (!string.Equals(context.HandlerMethod.Name, ForHandler, StringComparison.InvariantCultureIgnoreCase))
                {
                    await next.Invoke();
                }
            }

            if (!string.IsNullOrWhiteSpace(ForHttpMethod))
            {
                if (!string.Equals(context.HandlerMethod.HttpMethod, ForHttpMethod, StringComparison.InvariantCultureIgnoreCase))
                {
                    await next.Invoke();
                }
            }

            if (context.HandlerInstance is PageModel item)
            {
                context.ModelState.RetrieveFromTempData(TempKeyName, item.TempData);
            }

            await next.Invoke();
        }
예제 #2
0
        public async Task   OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            if (!context.ModelState.IsValid)
            {
                // Do Something
                if (!string.IsNullOrWhiteSpace(Handler))
                {
                    if (!string.Equals(context.HandlerMethod.Name, Handler, StringComparison.InvariantCultureIgnoreCase))
                    {
                        await next.Invoke();
                    }
                }

                if (!string.IsNullOrWhiteSpace(HttpMethod))
                {
                    if (!string.Equals(context.HandlerMethod.HttpMethod, HttpMethod, StringComparison.InvariantCultureIgnoreCase))
                    {
                        await next.Invoke();
                    }
                }

                SetPageResult(context);
            }
            else
            {
                await next.Invoke();
            }
        }
예제 #3
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            if (context.HttpContext.Request.Method.Equals("POST") || context.HttpContext.Request.Method.Equals("PUT"))
            {
                if (!context.ModelState.IsValid)
                {
                    //if(context.HttpContext.Request.IsAjaxRequest())
                    //{
                    //    var errorModel = context.ModelState.Keys.Where(x => context.ModelState[x].Errors.Count > 0)
                    //        .Select(x => new {
                    //            key = x,
                    //            errors = context.ModelState[x].Errors.Select(y => y.ErrorMessage).ToArray()
                    //        });

                    //    context.Result = new JsonResult(new AjaxResultHelper<IEnumerable<object>> {
                    //        Response = errorModel,
                    //        Message = "_InvalidData_"
                    //    });
                    //} else
                    //{
                    // TODO: For Page Submit
                    //var result = (PageResult)context.Result;

                    ////if (result is PageResult pageResult)
                    ////{
                    //context.Result = new PageResult
                    //{
                    //    ViewData = result.ViewData,
                    //    //Model = pageResult.Model,
                    //    ContentType = result.ContentType,
                    //    StatusCode = 400,
                    //    //Page = pageResult.Page
                    //};
                    ////}

                    //context.Result = new BadRequestObjectResult(context.ModelState);
                    //await next.Invoke();

                    var result = context.HandlerInstance as PageModel;

                    context.Result = new PageResult {
                        ViewData    = result?.ViewData,
                        ContentType = result?.Request.ContentType,
                        StatusCode  = 400,
                    };
                    //}
                }
                else
                {
                    await next.Invoke();
                }
            }
            else
            {
                await next.Invoke();
            }
        }
예제 #4
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            if (Configuration.AuditDisabled || IsActionIgnored(context))
            {
                await next.Invoke();

                return;
            }
            await BeforeExecutingAsync(context);

            var actionExecutedContext = await next.Invoke();

            await AfterExecutedAsync(actionExecutedContext);
        }
예제 #5
0
 /// <summary>
 /// Ons the page handler execution async.
 /// </summary>
 /// <returns>The page handler execution async.</returns>
 /// <param name="context">Context.</param>
 /// <param name="next">Next.</param>
 public async Task OnPageHandlerExecutionAsync(
     PageHandlerExecutingContext context,
     PageHandlerExecutionDelegate next)
 {
     _logger.LogDebug("Global OnPageHandlerExecutionAsync called.");
     await next.Invoke().ConfigureAwait(false);
 }
예제 #6
0
 public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
 {
     var ipAddress = context.HttpContext.Request.Host.ToString();
     var result    = (PageResult)context.Result;
     //result.ViewData["IpAddress"] = ipAddress;
     await next.Invoke();
 }
 public async Task OnPageHandlerExecutionAsync(
     PageHandlerExecutingContext context,
     PageHandlerExecutionDelegate next)
 {
     // Do post work.
     await next.Invoke();
 }
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            var ipAddress = context.HttpContext.Request.Host.ToString();
            //var countryCode = await _geoService.GetCountry(ipAddress);

            await next.Invoke();
        }
        /// <summary>
        /// Runs before page actions
        /// </summary>
        public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            LoggedInUser = await PuzzleUser.GetPuzzleUserForCurrentUser(_context, User, userManager);

            // Required to have the rest of page execution occur
            await next.Invoke();
        }
        public Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            ip = context.HttpContext.Connection.RemoteIpAddress;

            //page.ViewData["filterMessage"];
            return(next.Invoke());
            //throw new NotImplementedException();
        }
예제 #11
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context,
                                                      PageHandlerExecutionDelegate next)
        {
            var cacheAttribute = context.HandlerMethod.MethodInfo.GetCustomAttribute <ClientResponseCacheAttribute>();

            trySetHeaders(cacheAttribute, context.HttpContext);

            await next.Invoke();
        }
예제 #12
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context,
                                                      PageHandlerExecutionDelegate next)
        {
            await next.Invoke();

            var feature = new RouteDataProviderFeature(context.RouteData.Values);

            context.HttpContext.Features.Set(feature);
        }
예제 #13
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            if (context.HttpContext.Request.Method.Equals("POST") || context.HttpContext.Request.Method.Equals("PUT"))
            {
                if (!context.ModelState.IsValid)
                {
                    if (context.HttpContext.Request.IsAjaxRequest())
                    {
                        var errorModel = context.ModelState.Keys.Where(x => context.ModelState[x].Errors.Count > 0)
                                         .Select(x => new
                        {
                            key    = x,
                            errors = context.ModelState[x].Errors.Select(y => y.ErrorMessage).ToArray()
                        });

                        context.Result = new JsonResult(new AjaxResultHelper <IEnumerable <object> >
                        {
                            Response = errorModel,
                            Message  = "_InvalidData_"
                        });
                    }
                    else
                    {
                        var result = await next();

                        var provider = context.HttpContext.RequestServices.GetRequiredService <IModelMetadataProvider>();
                        var viewDataDictionaryModelType = context.ActionDescriptor.DeclaredModelTypeInfo ?? typeof(object);

                        //if (viewDataDictionaryModelType != null)
                        //{
                        //    Type _viewDataDictionaryType = typeof(ViewDataDictionary<>).MakeGenericType(viewDataDictionaryModelType);
                        //    _rootFactory = ViewDataDictionaryFactory.CreateFactory(viewDataDictionaryModelType.GetTypeInfo());
                        //    _nestedFactory = ViewDataDictionaryFactory.CreateNestedFactory(viewDataDictionaryModelType.GetTypeInfo());
                        //}

                        var factory        = ViewDataDictionaryFactory.CreateFactory(viewDataDictionaryModelType.GetTypeInfo());
                        var _nestedFactory = ViewDataDictionaryFactory.CreateNestedFactory(viewDataDictionaryModelType.GetTypeInfo());

                        var viewData    = factory(provider, context.ModelState);
                        var viewData2   = _nestedFactory(viewData);
                        var contentType = context.HttpContext.Request.ContentType;

                        context.Result = new PageResult
                        {
                            ViewData    = viewData,
                            ContentType = contentType,
                            StatusCode  = 400,
                        };
                    }
                }
            }
            else
            {
                await next.Invoke();
            }
        }
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context,
                                                      PageHandlerExecutionDelegate next)
        {
            await next.Invoke();

            var attributes = context.HandlerMethod.MethodInfo.GetCustomAttributes(false);
            var feature    = new PageHandlerAttributesProviderFeature(attributes);

            context.HttpContext.Features.Set(feature);
        }
예제 #15
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            var result = await next.Invoke();

            // If there was no exception, and the action wasn't cancelled, save changes.
            if (result.Exception == null && !result.Canceled)
            {
                await dbSession.SaveChangesAsync();
            }
        }
예제 #16
0
        public async override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context,
                                                               PageHandlerExecutionDelegate next)
        {
            var key = _config.GetValue(typeof(string), "UserAgentID");

            context.HttpContext.Request.Headers.TryGetValue("user-agent", out StringValues value);
            ProcessUserAgent.Write(context.ActionDescriptor.DisplayName,
                                   "/IndexModel-OnPageHandlerSelectionAsync",
                                   value, key.ToString());

            await next.Invoke();
        }
 public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context,
                                               PageHandlerExecutionDelegate next)
 {
     if (context.ModelState.IsValid)
     {
         await next.Invoke();
     }
     else
     {
         returnError(context.HttpContext);
     }
 }
예제 #18
0
        /// <summary>
        /// Override method for OnPageHandlerExecutionAsync.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            // check if user has access
            if (this.HasAccess())
            {
                // show page
                await next.Invoke();
            }

            // redirect to index page
            context.Result = new RedirectToPageResult("/Index");
        }
예제 #19
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context,
                                                      PageHandlerExecutionDelegate next)
        {
            var result = context.Result;

            if (result is PageResult)
            {
                var page = ((PageResult)result);
                page.ViewData["IP"] = "siema";
            }

            await next.Invoke();
        }
예제 #20
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            var ipAddress = context.HttpContext.Connection.RemoteIpAddress.MapToIPv4();

            var geo = await _geoService.GetCountry(ipAddress.ToString());

            if (geo != null && geo.ip != null)
            {
                _diagnosticContext.Set("Geo", geo, destructureObjects: true);
            }

            await next.Invoke();
        }
예제 #21
0
 public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
 {
     if (context.ModelState.IsValid)
     {
         await next.Invoke();
     }
     else
     {
         PageModel page = context.HandlerInstance as PageModel;
         context.Result = (IActionResult)page?.Page()
                          ?? new BadRequestResult();
     }
 }
예제 #22
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            //可以在这里模拟Action级别的Authorize授权,Razor Pages的Authorize授权只支持到PageModel级别
            //context.HandlerMethod.MethodInfo
            //context.Result

            var executedContext = await next.Invoke();

            //从这里开始相当于在IPageFilter的OnPageHandlerExecuted方法中执行代码
            //executedContext就是执行结果上下文

            await Task.CompletedTask;
        }
예제 #23
0
 public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
 {
     if (!context.ModelState.IsValid)
     {
         var result = new Dictionary <string, object>();
         var item   = context.ModelState.Values.ToList().Find(a => a.Errors.Count > 0);
         var msg    = item.Errors.Where(a => !string.IsNullOrEmpty(a.ErrorMessage)).Take(1).SingleOrDefault().ErrorMessage;
         result.Add("success", false);
         result.Add("msg", msg);
         context.Result = new JsonResult(result);
         return;
     }
     await next.Invoke();
 }
예제 #24
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            var http      = context.HttpContext;
            var db        = http.RequestServices.GetRequiredService <IDiagnosticsDbContext>();
            var principal = http.RequestServices.GetService <IPrincipalUser>();

            if (!http.Request.Query.ContainsKey("no_log"))
            {
                try {
                    await db.LogRequestAsync(http, principal);
                }
                catch { }
            }
            await next.Invoke();
        }
예제 #25
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            var db     = context.HttpContext.RequestServices.GetService <ProContext>();
            var member = await db.Members.FindAsync((uint)context.HttpContext.Session.GetInt32("username"));

            // Authority 필드가 0, 즉, 관리자여야 한다.
            // 일반 유저라면 권한 없음 알림
            if (member.Authority != 0)
            {
                context.Result = new StatusCodeResult(StatusCodes.Status403Forbidden);
            }
            else
            {
                await next.Invoke();
            }
        }
예제 #26
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!await AuthorizeAsync(context.HttpContext))
            {
                context.Result = new ChallengeResult();
                return;
            }

            // Do post work.
            await next.Invoke();
        }
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            //在调用处理程序方法前,但在模型绑定结束后,进行异步调用。

            //context.ActionDescriptor.FilterDescriptors
            var authenticateResult = await context.HttpContext.AuthenticateAsync(AdminAuthorizeAttribute.AuthenticationScheme);

            if (authenticateResult.Succeeded && !context.Filters.Any(_ => _ is AllowAnonymousFilter))
            {
                AdminPageModelBase adminPageModel = context.HandlerInstance as AdminPageModelBase;
                //adminPageModel.SysMenuDtos = await _sysMenuService.GetMenuTreeDtoByCacheAsync();
                adminPageModel.AdminWorkContext = _adminWorkContextProvider.GetAdminWorkContext();

                bool hasPageRoute = context.RouteData.Values.TryGetValue("page", out object page);
                bool hasAreaRoute = context.RouteData.Values.TryGetValue("area", out object area);

                bool hasRight = hasPageRoute && hasAreaRoute;
                if (hasRight)
                {
                    var url = context.HttpContext.Request.Path; /*.GetEncodedPathAndQuery()*/;
                    hasRight = await _sysPermissionService.HasPermissionAsync(url /*string.Concat("/", area, page)*/);
                }

                if (!hasRight /*&& !(adminPageModel is Pages.IndexModel)*/)
                {
                    IActionResult actionResult = new Microsoft.AspNetCore.Mvc.RedirectResult("/Admin/Forbidden");
                    //跳出
                    if (context.HttpContext.Request.Headers.TryGetValue("x-requested-with", out Microsoft.Extensions.Primitives.StringValues strings))
                    {
                        if (strings.Contains("XMLHttpRequest"))
                        {
                            actionResult = new JsonResult(new AjaxReturnModel()
                            {
                                Success = false, Msg = "您没有权限访问"
                            })
                            {
                                StatusCode = 401
                            };
                        }
                    }
                    context.Result = actionResult;
                    return;//If an IAsyncPageFilter provides a result value by setting the Result property of PageHandlerExecutingContext to a non-null value, then it cannot call the next filter by invoking PageHandlerExecutionDelegate.
                }
            }
            await next.Invoke();
        }
예제 #28
0
 public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context,
                                               PageHandlerExecutionDelegate next)
 {
     try
     {
         // Do post work.
         await next.Invoke();
     }
     catch (AppError ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
예제 #29
0
        public async Task OnPageHandlerExecutionAsync(
            PageHandlerExecutingContext context,
            PageHandlerExecutionDelegate next)
        {
            // Check user agent
            string userAgent = context.HttpContext.Request.Headers["User-Agent"];

            foreach (string client in _rejectedClients)
            {
                if (userAgent.Contains(client))
                {
                    context.Result = new NotFoundResult();
                    await Task.CompletedTask;
                    break;
                }
            }
            await next.Invoke();
        }
예제 #30
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            if (context.HttpContext.Request.Method.ToLower() == "post")
            {
                var gurdGuid = context.HttpContext.Request.Form["__RequestVerificationToken"];

                if (!string.IsNullOrEmpty(gurdGuid))
                {
                    if (GurdGuids.Contains(gurdGuid))
                    {
                        context.Result = new RedirectResult("/MultiPost");
                        return;
                    }
                    else
                    {
                        GurdGuids.Add(gurdGuid);
                    }
                }
            }
            await next.Invoke();
        }