public async Task OnActionExecutionAsync(ActionExecutingContext context, 
     ActionExecutionDelegate next)
 {
     // do something before the action executes
     await next();
     // do something after the action executes
 }
        public static void ActionMethodExecuting(this ILogger logger, ActionExecutingContext context, object[] arguments)
        {
            if (logger.IsEnabled(LogLevel.Information))
            {
                var actionName = context.ActionDescriptor.DisplayName;

                string[] convertedArguments;
                if (arguments == null)
                {
                    convertedArguments = null;
                }
                else
                {
                    convertedArguments = new string[arguments.Length];
                    for (var i = 0; i < arguments.Length; i++)
                    {
                        convertedArguments[i] = Convert.ToString(arguments[i]);
                    }
                }

                var validationState = context.ModelState.ValidationState;

                _actionMethodExecuting(logger, actionName, convertedArguments, validationState, null);
            }
        }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            string cultureName;
            var request = context.HttpContext.Request;
            var cultureCookie = request.Cookies[CultureCookieName];

            if (cultureCookie.Any())
            {
                cultureName = cultureCookie[0];
            }
            else
            {
                cultureName = request.Headers["Accept-Language"];
                var cultures = CultureHelper.ParserHeaderAcceptedLanguage(cultureName);

                var cultureFirst = cultures?.FirstOrDefault();
                if (cultureFirst != null)
                    cultureName = cultureFirst.Value;

                cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe

                context.HttpContext.Response.Cookies.Append(CultureCookieName, cultureName);

            }

            _logger.LogInformation($"Setting the culture from the URL: {cultureName}");


            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);

            base.OnActionExecuting(context);
        }
		public override async Task OnActionExecutionAsync(ActionExecutingContext startContext, ActionExecutionDelegate next)
		{
			_stopwatch = Stopwatch.StartNew();

			var endContext = await next();

			Debug.WriteLine($"Action ended in {_stopwatch.Elapsed}");
		}
        protected override Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext)
        {
            var actionInfo = _module.Actions[_descriptor.Index];

            var value = actionInfo.Func();

            var actionResult = CreateActionResult(value);
            return Task.FromResult(actionResult);
        }
 public override void OnActionExecuting(ActionExecutingContext context)
 {
     var names = context.HttpContext.Request.Query["name"];
     if (names.Any())
     {
         var module = (MvcModule)context.Controller;
         module.ViewData.Add("name", names.First());
     }
 }
Exemplo n.º 7
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            Apply(context.HttpContext);

            // TODO: Check permission
            //if (!_authorizer.Authorize(StandardPermissions.AccessAdminPanel, T("Can't access the admin")))
            //{
            //    filterContext.Result = new HttpUnauthorizedResult();
            //}
        }
Exemplo n.º 8
0
 /// <summary>
 /// Returns <c>true</c> if the controller name starts with Admin or if the <see cref="AdminAttribute"/>
 /// is applied to the controller or the action.
 /// </summary>
 private static bool IsAdmin(ActionExecutingContext context)
 {
     // Does the controller start with "Admin"
     if (IsNameAdmin(context))
     {
         return true;
     }
     
     return false;
 }
Exemplo n.º 9
0
            public void OnActionExecuting(ActionExecutingContext context)
            {
                if (!context.ActionArguments.Any()) return;

                //put the model in the context, we'll resolve that after it's executed
                var file = context.ActionArguments.First().Value as RequestModel;
                if (file != null)
                {
                    context.HttpContext.Items[nameof(AddExpiryHeadersAttribute)] = file;
                }
            }
 public void OnActionExecuting(ActionExecutingContext context)
 {
     if (context.ActionDescriptor.DisplayName == "FiltersSample.Controllers.HomeController.Hello")
     {
         // Manipulating action arguments...
         if (!context.ActionArguments.ContainsKey("name"))
         {
             context.ActionArguments["name"] = "Steve";
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// See base class documentation.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        public override void OnActionExecuting(ActionExecutingContext actionContext)
        {
            var context = new PaginationContext(
                actionContext.HttpContext.Request.GetQueryNameValuePairs(),
                PerPage);

            var query = GetQueryContext(actionContext);

            query.Pagination = context;
            base.OnActionExecuting(actionContext);
        }
 public override void OnActionExecuting(ActionExecutingContext context)
 {
     try
     {
       
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 13
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            object originalUserName = null;

            context.ActionArguments.TryGetValue("userName", out originalUserName);

            var userName = originalUserName as string;

            if (string.IsNullOrWhiteSpace(userName))
            {
                context.ActionArguments["userName"] = _nameService.GetName();
            }
        }
        /// <summary>
        /// See base class documentation.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        public override void OnActionExecuting(ActionExecutingContext actionContext)
        {
            var queryParams = actionContext.HttpContext.Request.GetQueryNameValuePairs();
            var sorting = new SortingContext(queryParams);
            var filtering = new FilteringContext(queryParams);

            var queryContext = GetQueryContext(actionContext);

            queryContext.Sorting = sorting;
            queryContext.Filtering = filtering;

            base.OnActionExecuting(actionContext);
        }
Exemplo n.º 15
0
        protected override async Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext)
        {
            var actionMethodInfo = _descriptor.MethodInfo;
            var actionReturnValue = await ControllerActionExecutor.ExecuteAsync(
                actionMethodInfo,
                actionExecutingContext.Controller,
                actionExecutingContext.ActionArguments);

            var actionResult = CreateActionResult(
                actionMethodInfo.ReturnType,
                actionReturnValue);
            return actionResult;
        }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            string culture = context.RouteData.Values["culture"].ToString();
            _logger.LogInformation($"Setting the culture from the URL: {culture}");

            #if DNX451
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
            #else
            CultureInfo.CurrentCulture = new CultureInfo(culture);
            CultureInfo.CurrentUICulture = new CultureInfo(culture);
            #endif
            base.OnActionExecuting(context);
        }
        private static QueryContext GetQueryContext(ActionExecutingContext actionContext)
        {
            var hasQuery = actionContext.HttpContext.Items.ContainsKey(Constants.QueryContextPropertyName);
            QueryContext query;

            if (hasQuery)
            {
                query = actionContext.HttpContext.Items[Constants.QueryContextPropertyName]
                    as QueryContext;
            }
            else
            {
                query = new QueryContext();
                actionContext.HttpContext.Items.Add(Constants.QueryContextPropertyName, query);
            }

            return query;
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            Uri redirectUrl;
            switch (SharePointContextProvider.CheckRedirectionStatus(filterContext.HttpContext, out redirectUrl))
            {
                case RedirectionStatus.Ok:
                    return;
                case RedirectionStatus.ShouldRedirect:
                    filterContext.Result = new RedirectResult(redirectUrl.AbsoluteUri);
                    break;
                case RedirectionStatus.CanNotRedirect:
                    filterContext.Result = new ViewResult { ViewName = "Error" };
                    break;
            }
        }
Exemplo n.º 19
0
        public virtual async Task OnActionExecutionAsync(
            ActionExecutingContext context,
            ActionExecutionDelegate next)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            OnActionExecuting(context);
            if (context.Result == null)
            {
                OnActionExecuted(await next());
            }
        }
Exemplo n.º 20
0
        /// <inheritdoc />
        public async Task OnActionExecutionAsync(
            ActionExecutingContext context,
            ActionExecutionDelegate next)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            var controller = context.Controller;
            if (controller == null)
            {
                throw new InvalidOperationException(Resources.FormatPropertyOfTypeCannotBeNull(
                    nameof(context.Controller),
                    nameof(ActionExecutingContext)));
            }

            IAsyncActionFilter asyncActionFilter;
            IActionFilter actionFilter;
            if ((asyncActionFilter = controller as IAsyncActionFilter) != null)
            {
                await asyncActionFilter.OnActionExecutionAsync(context, next);
            }
            else if ((actionFilter = controller as IActionFilter) != null)
            {
                actionFilter.OnActionExecuting(context);
                if (context.Result == null)
                {
                    actionFilter.OnActionExecuted(await next());
                }
            }
            else
            {
                await next();
            }
        }
        public void OnActionExecuting_IsNoOp()
        {
            // Arrange
            var filter = new HttpResponseExceptionActionFilter();

            var actionContext = new ActionContext(
                                new DefaultHttpContext(),
                                new RouteData(),
                                Mock.Of<ActionDescriptor>());

            var context = new ActionExecutingContext(
                actionContext,
                filters: new List<IFilterMetadata>(),
                actionArguments: new Dictionary<string, object>(),
                controller: new object());

            // Act
            filter.OnActionExecuting(context);

            // Assert
            Assert.Null(context.Result);
        }
Exemplo n.º 22
0
        public override void OnActionExecuting(ActionExecutingContext context)
        { 
            base.OnActionExecuting(context);

            if (context.ActionDescriptor == null) return;
            if (context.ActionDescriptor.FilterDescriptors == null) return;
            if (context.IsActionDefined<IgnoreDataScopedAttribute>()) return;

            var first = GetFirst(context.ActionDescriptor.FilterDescriptors);
            if (first != this) return;

            this.Callback = GetCallback(context);

            this.IsEnabled = true;

            if (this.UseTransaction)
            {
                this.TransactionScope = TxManager.Acquire();
                this.Callback.AfterEnter(TransactionScope);
            }

            this.Session = this.Callback.SessionProvider.GetSession();
            this.Callback.AfterEnter(this.Session);
        }
 public override void OnActionExecuting(ActionExecutingContext context)
 {
     _logger.LogWarning("ClassFilter OnActionExecuting");
     base.OnActionExecuting(context);
 }
Exemplo n.º 24
0
 public virtual void OnActionExecuting(ActionExecutingContext context)
 {
 }
Exemplo n.º 25
0
        private static IDataScopedCallback GetCallback(ActionExecutingContext context)
        {
            if (context == null) throw new ArgumentNullException(nameof(context));

            if (context.Controller == null)
            {
                throw new InvalidOperationException("Unexpected context, the context.Controller is null.");
            }

            var controllerName = context.Controller.GetType().FullName;

            var result = context.Controller as IDataScopedCallback;
            if (result == null)
            {
                throw new InvalidOperationException($"The {controllerName} should implement {m_CallbackName}.");
            }
            if (result.SessionProvider == null)
            {
                throw new InvalidOperationException($"The {controllerName} should provide an {m_FactoryName}.");
            }
            return result;
        }
 public void OnActionExecuting(ActionExecutingContext context)
 {
     context.ActionArguments["randomNumber"] = _dummyService.RandomNumber;
 }
Exemplo n.º 27
0
 public override void OnActionExecuting(ActionExecutingContext context)
 {
     throw new InvalidProgramException("Action Filter threw");
 }
Exemplo n.º 28
0
 public override void OnActionExecuting(ActionExecutingContext actionContext)
 {
     _exampleService.LogRequestStub("The request was: " + actionContext.HttpContext.Request);
 }
Exemplo n.º 29
0
 public override void OnActionExecuting(ActionExecutingContext actionContext)
 {
     //this.logger.Log(actionContext.HttpContext.Request);
     var somethingICouldLog = actionContext.HttpContext.Request;
 }
Exemplo n.º 30
0
 public void OnActionExecuting(ActionExecutingContext context)
 {
     var paramterValue = (int)context.ActionArguments["randomNumber"];
     context.ActionArguments["randomNumber"] = paramterValue + _random.GetRandamNumber();
 }