/// <summary>
        /// 获取动作的参数
        /// </summary>
        /// <param name="controllerContext"></param>
        /// <param name="actionDescriptor"></param>
        /// <returns></returns>
        protected virtual IDictionary <string, object> GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            var context = controllerContext.HttpContext;
            IActionParametersProvider provider = ActionParametersProviderFactory.CreateActionParametersProvider(context.Request);

            return(provider.GetParameters(context.Request, actionDescriptor));
        }
Exemple #2
0
        private static object[] GetActionCallParameters(HttpContext context, ActionDescription action)
        {
            if (action.Parameters == null || action.Parameters.Length == 0)
            {
                return(null);
            }

            IActionParametersProvider provider = ActionParametersProviderFactory.CreateActionParametersProvider(context.Request);

            return(provider.GetParameters(context.Request, action));
        }
Exemple #3
0
        /// <summary>
        /// 获取当前执行的Action信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public BehaviorActionInfo GetActionInfo(HttpContext context)
        {
            bool isAjaxRequest        = string.Compare(context.Request.Headers["X-Requested-With"], "XMLHttpRequest", StringComparison.OrdinalIgnoreCase) == 0;
            BehaviorActionInfo action = new BehaviorActionInfo();
            InvokeInfo         vkInfo = null;

            if (isAjaxRequest)
            {
                string vPath = UrlHelper.GetRealVirtualPath(context, context.Request.Path);

                ControllerActionPair pair = new AjaxHandlerFactory().ParseUrl(context, vPath);
                if (pair == null)
                {
                    ExceptionHelper.Throw404Exception(context);
                }

                // 获取内部表示的调用信息
                vkInfo = ReflectionHelper.GetActionInvokeInfo(pair, context.Request);
            }
            else
            {
                string requestPath = context.Request.Path;
                string vPath       = UrlHelper.GetRealVirtualPath(context, requestPath);
                // 尝试根据请求路径获取Action
                vkInfo = ReflectionHelper.GetActionInvokeInfo(vPath);
            }
            if (vkInfo != null)
            {
                action.ActionName     = vkInfo.Action.MethodInfo.Name;
                action.ControllerName = vkInfo.Controller.ControllerType.Name;

                object[] Values = ActionParametersProviderFactory.CreateActionParametersProvider(context).GetParameters(context, vkInfo.Action);


                for (int i = 0; i < vkInfo.Action.Parameters.Length; i++)
                {
                    action.Parameters.Add(new { Name = vkInfo.Action.Parameters[i].Name, Value = Values[i] });
                }
            }
            return(action);
        }