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"));
        }
Esempio n. 2
0
        protected ActionResult Route <TController>(string routeName,
                                                   Expression <Action <TController> > action, string suffix)
            where TController : IController
        {
            Precondition.Require(action, () => Error.ArgumentNull("action"));

            MethodCallExpression mexp = (action.Body as MethodCallExpression);

            if (mexp == null)
            {
                throw Error.ExpressionMustBeAMethodCall("action");
            }

            if (mexp.Object != action.Parameters[0])
            {
                throw Error.MethodCallMustTargetLambdaArgument("action");
            }

            ValueDictionary values = LinqHelper.ExtractArgumentsToDictionary(mexp);

            values = (values != null) ? values : new ValueDictionary();

            values["controller"] = typeof(TController).Name;
            values["action"]     = ActionMethodSelector.GetNameOrAlias(mexp.Method);

            return(Route(routeName, values, suffix));
        }
Esempio n. 3
0
        /// <summary>
        /// Convenience method used to generate a link
        /// using Routing to determine the virtual path.
        /// </summary>
        /// <param name="routeKey">The name of the route, if any.</param>
        /// <param name="action">The action with parameters.</param>
        /// <typeparam name="TController">The type of the controller.</typeparam>
        public virtual string Route <TController>(string routeKey,
                                                  Expression <Action <TController> > action)
            where TController : IController
        {
            Precondition.Require(action, () => Error.ArgumentNull("action"));

            MethodCallExpression mexp = (action.Body as MethodCallExpression);

            if (mexp == null)
            {
                throw Error.ExpressionMustBeAMethodCall("action");
            }

            if (mexp.Object != action.Parameters[0])
            {
                throw Error.MethodCallMustTargetLambdaArgument("action");
            }

            string actionName     = ActionMethodSelector.GetNameOrAlias(mexp.Method);
            string controllerName = typeof(TController).Name;

            ValueDictionary rvd = LinqHelper.ExtractArgumentsToDictionary(mexp);

            rvd = (rvd != null) ? rvd : new ValueDictionary();

            return(HttpUtility.HtmlAttributeEncode(GenerateUrl(routeKey, controllerName, actionName, rvd)));
        }
Esempio n. 4
0
        protected virtual void Include <TController>(Expression <Action <TController> > action)
            where TController : Controller
        {
            MethodCallExpression mce = (action.Body as MethodCallExpression);

            Precondition.Require(mce, () => Error.ExpressionMustBeAMethodCall("action"));
            Precondition.Require(mce.Object == action.Parameters[0],
                                 () => Error.MethodCallMustTargetLambdaArgument("action"));

            Include(typeof(TController).Name,
                    ActionMethodSelector.GetNameOrAlias(mce.Method),
                    LinqHelper.ExtractArgumentsToDictionary(mce));
        }
        public static Route MapRoute <TController>(this RouteCollection routes,
                                                   string key, string url, Expression <Action <TController> > action,
                                                   object tokens, params IRouteConstraint[] constraints)
            where TController : IController
        {
            Precondition.Require(routes, () => Error.ArgumentNull("routes"));
            Precondition.Require(url, () => Error.ArgumentNull("url"));

            MethodCallExpression mexp = (action.Body as MethodCallExpression);

            if (mexp == null)
            {
                throw Error.ExpressionMustBeAMethodCall("action");
            }

            if (mexp.Object != action.Parameters[0])
            {
                throw Error.MethodCallMustTargetLambdaArgument("action");
            }

            string actionName     = ActionMethodSelector.GetNameOrAlias(mexp.Method);
            string controllerName = typeof(TController).Name;

            ValueDictionary defaults = LinqHelper.ExtractArgumentsToDictionary(mexp);

            if (defaults == null)
            {
                defaults = new ValueDictionary();
            }

            defaults["controller"] = controllerName;
            defaults["action"]     = actionName;

            constraints = constraints ?? new IRouteConstraint[0];

            Route route = new Route(url, defaults, constraints,
                                    new ValueDictionary(tokens), new MvcRouteHandler());

            routes.Add(key, route);
            return(route);
        }