Beispiel #1
0
 /// <summary>
 /// 在控制器的标记验证失败时要执行的操作
 /// </summary>
 /// <param name="failedAttribute"></param>
 /// <returns></returns>
 protected virtual DecisiveOperatingInstruction OnControllerAttributeValidateFailed(AttributeBase failedAttribute)
 {
     if (failedAttribute is AuthenticationAttribute)
     {
         if (Request.IsAuthenticated)
         {
             Response.Send403();
         }
         else
         {
             Response.Send401();
         }
         return(DecisiveOperatingInstruction.Abort());
     }
     else if (failedAttribute is HttpMethodAttribute)
     {
         var httpAttr = 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);
         }
         return(DecisiveOperatingInstruction.Abort());
     }
     else if (failedAttribute is SecureConnectionAttribute)
     {
         return(DecisiveOperatingInstruction.ThrowException(new HttpException(
                                                                string.Format("只有在使用安全的 HTTP 连接时,才可以请求控制器 \"{0}\" 中的 Action", Name, ControllerContext.ActionName))));
     }
     return(DecisiveOperatingInstruction.NoOperation());
 }
Beispiel #2
0
 /// <summary>
 /// 在执行请求的操作方法出错时要执行的操作
 /// </summary>
 /// <param name="baseException"></param>
 /// <returns></returns>
 protected virtual DecisiveOperatingInstruction OnActionExecutionError(Exception baseException)
 {
     return(DecisiveOperatingInstruction.ThrowException(
                new Exception(string.Format("在执行控制器 \"{0}\" 的 \"{1}\" Action 时遇到错误", Name, ControllerContext.ActionName), baseException)));
 }
Beispiel #3
0
 /// <summary>
 /// 当请求的操作方法未找到时要执行的操作
 /// </summary>
 protected virtual DecisiveOperatingInstruction OnActionNotFound()
 {
     return(DecisiveOperatingInstruction.ThrowException(
                new Exception(string.Format("控制器 \"{0}\" 中不存在名为 \"{1}\" 的 Action", Name, ControllerContext.ActionName))));
 }