/// <summary>
 /// 依据当前Http路由请求和处理请求的控制器信息获取操作方法信息
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public virtual ActionMethodInfo GetActionMethod(ControllerContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     else
     {
         var newSelector = new NonParameterActionMethodSelector(context);
         var action = newSelector.GetActionMethod(ActionFlags);
         if (action != null && action.Attributes != null)
         {
             foreach (var attr in action.Attributes)
             {
                 if (!attr.Validate(context.HttpContext))
                 {
                     var eventArgs =
                         new ActionAttributeValidateFailedEventArgs(context.Controller.Name, context.ActionName, attr);
                     this._ActionAttributeValidateFailed(context.Controller, eventArgs);
                     break;
                 }
             }
         }
         return action;
     }
 }
 /// <summary>
 /// 依据当前Http路由请求和处理请求的控制器信息获取操作方法信息
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public virtual ActionMethodInfo GetActionMethod(ControllerContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     else
     {
         var newSelector = new NonParameterActionMethodSelector(context);
         var action      = newSelector.GetActionMethod(ActionFlags);
         if (action != null && action.Attributes != null)
         {
             foreach (var attr in action.Attributes)
             {
                 if (!attr.Validate(context.HttpContext))
                 {
                     var eventArgs =
                         new ActionAttributeValidateFailedEventArgs(context.Controller.Name, context.ActionName, attr);
                     this._ActionAttributeValidateFailed(context.Controller, eventArgs);
                     break;
                 }
             }
         }
         return(action);
     }
 }
        /// <summary>
        /// 在请求的操作方法的Action标记验证失败时要执行的操作
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        protected virtual void OnActionAttributeValidateFailed(object controller, ActionAttributeValidateFailedEventArgs e)
        {
            var Response = ((IController)controller).ControllerContext.HttpContext.Response;
            var Request  = ((IController)controller).ControllerContext.HttpContext.Request;

            if (e.FailedAttribute is HttpMethodAttribute)
            {
                var httpAttr = e.FailedAttribute as HttpMethodAttribute;
                if (!string.IsNullOrEmpty(httpAttr.RedirectUrl))
                {
                    string url =
                        httpAttr.ReserveQueryString ? httpAttr.RedirectUrl + Request.Url.Query : httpAttr.RedirectUrl;
                    Response.Redirect(url);
                }
                else
                {
                    Response.Send405(httpAttr.Allow);
                }
            }
            else if (e.FailedAttribute is AuthenticationAttribute)
            {
                if (Request.IsAuthenticated)
                {
                    Response.Send403();
                }
                else
                {
                    Response.Send401();
                }
            }
            else if (e.FailedAttribute is SecureConnectionAttribute)
            {
                throw new HttpException(
                          string.Format("只有在使用安全的 HTTP 连接时,才可以请求控制器 \"{0}\" 中的 \"{1}\" Action", e.ControllerName, e.ActionName));
            }
        }
        /// <summary>
        /// 在请求的操作方法的Action标记验证失败时要执行的操作
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        protected virtual void OnActionAttributeValidateFailed(object controller, ActionAttributeValidateFailedEventArgs e)
        {
            var Response = ((IController)controller).ControllerContext.HttpContext.Response;
            var Request = ((IController)controller).ControllerContext.HttpContext.Request;

            if (e.FailedAttribute is HttpMethodAttribute)
            {
                var httpAttr = e.FailedAttribute as HttpMethodAttribute;
                if (!string.IsNullOrEmpty(httpAttr.RedirectUrl))
                {
                    string url =
                        httpAttr.ReserveQueryString ? httpAttr.RedirectUrl + Request.Url.Query : httpAttr.RedirectUrl;
                    Response.Redirect(url);
                }
                else
                {
                    Response.Send405(httpAttr.Allow);
                }
            }
            else if (e.FailedAttribute is AuthenticationAttribute)
            {
                if (Request.IsAuthenticated)
                {
                    Response.Send403();
                }
                else
                {
                    Response.Send401();
                }
            }
            else if (e.FailedAttribute is SecureConnectionAttribute)
            {
                throw new HttpException(
                    string.Format("只有在使用安全的 HTTP 连接时,才可以请求控制器 \"{0}\" 中的 \"{1}\" Action", e.ControllerName, e.ActionName));
            }
        }
 /// 当获取的操作方法的Action标记验证失败时要执行的操作
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 protected virtual void OnActionAttributeValidateFailed(object controller, ActionAttributeValidateFailedEventArgs e)
 {
 }
 /// 当获取的操作方法的Action标记验证失败时要执行的操作
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 protected virtual void OnActionAttributeValidateFailed(object controller, ActionAttributeValidateFailedEventArgs e)
 {
 }