public override void OnExecuting(ActionExecutionContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));

            string cultureCode = GetCultureCode(context);
            if (!String.IsNullOrEmpty(cultureCode))
            {
                // remove the qualifier value
                cultureCode = cultureCode.Split(new char[] { ';' }, 
                    StringSplitOptions.RemoveEmptyEntries)[0];

                try
                {
                    CultureInfo culture; int lcid;

                    culture = (int.TryParse(cultureCode, NumberStyles.Integer,
                        CultureInfo.InvariantCulture, out lcid)) ?
                            CultureInfo.GetCultureInfo(lcid) :
                            CultureInfo.CreateSpecificCulture(cultureCode);

                    Thread.CurrentThread.CurrentCulture = culture;
                    Thread.CurrentThread.CurrentUICulture = culture;
                }
                catch (ArgumentException)
                { }
                catch (NotSupportedException)
                { }
            }
        }
        public override void OnExecuting(ActionExecutionContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));

            string cultureCode = GetCultureCode(context);

            if (!String.IsNullOrEmpty(cultureCode))
            {
                // remove the qualifier value
                cultureCode = cultureCode.Split(new char[] { ';' },
                                                StringSplitOptions.RemoveEmptyEntries)[0];

                try
                {
                    CultureInfo culture; int lcid;

                    culture = (int.TryParse(cultureCode, NumberStyles.Integer,
                                            CultureInfo.InvariantCulture, out lcid)) ?
                              CultureInfo.GetCultureInfo(lcid) :
                              CultureInfo.CreateSpecificCulture(cultureCode);

                    Thread.CurrentThread.CurrentCulture   = culture;
                    Thread.CurrentThread.CurrentUICulture = culture;
                }
                catch (ArgumentException)
                { }
                catch (NotSupportedException)
                { }
            }
        }
예제 #3
0
        private static ActionExecutedContext InvokeActionFilter(IActionFilter filter, 
            ActionExecutionContext context, Func<ActionExecutedContext> continuation)
        {
            filter.OnExecuting(context);
            if (context.Cancel)
                return new ActionExecutedContext(context, null) { 
					Result = context.Result 
				};

            bool wasError = false;
            ActionExecutedContext postContext = null;
            try
            {
                postContext = continuation();
            }
            catch (Exception ex)
            {
                wasError = true;
                postContext = new ActionExecutedContext(context, ex);
                filter.OnExecuted(postContext);

                if (!postContext.ExceptionHandled)
                    throw;
            }
            if (!wasError)
                filter.OnExecuted(postContext);
            
            return postContext;
        }
        protected virtual string CreateCacheKey(ActionExecutionContext context)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(context.Action.Method.ReflectedType.FullName)
            .Append("::").Append(ActionMethodSelector.GetNameOrAlias(context.Action.Method));

            sb.Append("=>{");

            IEnumerable <string> collection = (_matchAnyKey) ?
                                              (IEnumerable <string>)context.Context.Parameters.Keys : _keys;

            foreach (string key in collection)
            {
                sb.Append(CreateParameterKey(context.Context.Parameters, key));
            }

            if (_varyByUser)
            {
                sb.Append("[UserIdentity=").Append(GetUserIdentity(context.HttpContext)).Append("]");
            }

            sb.Append("}");
            return(FormsAuthentication.HashPasswordForStoringInConfigFile(sb.ToString(), "MD5"));
        }
예제 #5
0
 public override void OnExecuting(ActionExecutionContext context)
 {
     Precondition.Require(context, () => Error.ArgumentNull("context"));
     if (context.HttpContext.Items[_storeKey] == null)
     {
         context.HttpContext.Response.ContentType = _contentType;
         context.HttpContext.Items[_storeKey]     = true;
     }
 }
 public override void OnExecuting(ActionExecutionContext context)
 {
     Precondition.Require(context, () => Error.ArgumentNull("context"));
     if (context.HttpContext.Items[_storeKey] == null)
     {
         context.HttpContext.Response.ContentType = _contentType;
         context.HttpContext.Items[_storeKey] = true;
     }
 }
        public override void OnExecuting(ActionExecutionContext context)
        {
            _cacheKey = CreateCacheKey(context);
            ActionResult cachedResult = GetCachedValue <ActionResult>(_cacheKey);

            if (cachedResult != null)
            {
                context.Cancel = true;
                context.Result = cachedResult;
            }
        }
예제 #8
0
        public override void OnExecuting(ActionExecutionContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            HttpResponseBase response = context.HttpContext.Response;

            response.Cache.SetCacheability(_cacheability);
            response.Cache.SetRevalidation(_revalidation);
            response.Cache.SetExpires(DateTime.Now.AddSeconds(_duration));
            response.Cache.SetMaxAge(TimeSpan.FromSeconds(_duration));
            response.Cache.SetETagFromFileDependencies();
        }
        public override void OnExecuting(ActionExecutionContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
			HttpResponseBase response = context.HttpContext.Response;

            response.Cache.SetCacheability(_cacheability);
            response.Cache.SetRevalidation(_revalidation);
            response.Cache.SetExpires(DateTime.Now.AddSeconds(_duration));
            response.Cache.SetMaxAge(TimeSpan.FromSeconds(_duration));
            response.Cache.SetETagFromFileDependencies();
        }
		public override void OnExecuting(ActionExecutionContext context)
		{
			_cacheKey = CreateCacheKey(context);
			string cachedResult = GetCachedValue<string>(_cacheKey);

			if (cachedResult != null)
			{
				_suppressResultFiltering = true;

				context.Cancel = true;
				context.Result = new ContentResult() {
					Content = cachedResult
				};
			}
		}
예제 #11
0
        public override void OnExecuting(ActionExecutionContext context)
        {
            _cacheKey = CreateCacheKey(context);
            string cachedResult = GetCachedValue <string>(_cacheKey);

            if (cachedResult != null)
            {
                _suppressResultFiltering = true;

                context.Cancel = true;
                context.Result = new ContentResult()
                {
                    Content = cachedResult
                };
            }
        }
예제 #12
0
        protected virtual ActionExecutedContext InvokeActionFilters(
            ControllerContext context, ActionDescriptor action,
            ICollection <IActionFilter> filters)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(action, () => Error.ArgumentNull("action"));
            Precondition.Require(filters, () => Error.ArgumentNull("filters"));

            ActionExecutionContext       exc          = new ActionExecutionContext(context, action);
            Func <ActionExecutedContext> continuation = () =>
                                                        new ActionExecutedContext(exc, null)
            {
                Result = InvokeActionMethod(context, action, context.Parameters)
            };

            Func <ActionExecutedContext> thunk = filters.Reverse().Aggregate(continuation,
                                                                             (next, filter) => () => InvokeActionFilter(filter, exc, next));

            return(thunk());
        }
예제 #13
0
        private static ActionExecutedContext InvokeActionFilter(IActionFilter filter,
                                                                ActionExecutionContext context, Func <ActionExecutedContext> continuation)
        {
            filter.OnExecuting(context);
            if (context.Cancel)
            {
                return new ActionExecutedContext(context, null)
                       {
                           Result = context.Result
                       }
            }
            ;

            bool wasError = false;
            ActionExecutedContext postContext = null;

            try
            {
                postContext = continuation();
            }
            catch (Exception ex)
            {
                wasError    = true;
                postContext = new ActionExecutedContext(context, ex);
                filter.OnExecuted(postContext);

                if (!postContext.ExceptionHandled)
                {
                    throw;
                }
            }
            if (!wasError)
            {
                filter.OnExecuted(postContext);
            }

            return(postContext);
        }
		public virtual void OnExecuting(ActionExecutionContext context)
		{
		}
예제 #15
0
 public virtual void OnExecuting(ActionExecutionContext context)
 {
 }
예제 #16
0
        protected virtual ActionExecutedContext InvokeActionFilters(
            ControllerContext context, ActionDescriptor action, 
            ICollection<IActionFilter> filters)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(action, () => Error.ArgumentNull("action"));
            Precondition.Require(filters, () => Error.ArgumentNull("filters"));
            
            ActionExecutionContext exc = new ActionExecutionContext(context, action);
            Func<ActionExecutedContext> continuation = () =>
                new ActionExecutedContext(exc, null) { 
					Result = InvokeActionMethod(context, action, context.Parameters) 
				};

            Func<ActionExecutedContext> thunk = filters.Reverse().Aggregate(continuation,
                (next, filter) => () => InvokeActionFilter(filter, exc, next));
            return thunk();
        }
예제 #17
0
 /// <summary>
 /// Method called before the action method is invoked.
 /// </summary>
 /// <param name="context">Contains information about the current request and action</param>
 protected virtual void OnPreAction(ActionExecutionContext context)
 {
 }
예제 #18
0
 void IActionFilter.OnExecuting(ActionExecutionContext context)
 {
     OnPreAction(context);
 }