当前位置:编程学习 > asp >>

asp.net mvc源码分析-Controllerl篇 ControllerDescriptor

 public IActionInvoker ActionInvoker {
            get {
                if (_actionInvoker == null) {
                    _actionInvoker = CreateActionInvoker();
                }
                return _actionInvoker;
            }
            set {
                _actionInvoker = value;
            }
        }
 protected virtual IActionInvoker CreateActionInvoker() {
            return new ControllerActionInvoker();
        }


和TempDataProvider属性定义一样,大家一定要习惯这些代码啊。

而ControllerActionInvoker的定义也很简单,但是这个类却不简单啊。

让我们来看看你InvokeAction的定义吧:


[csharp]
public virtual bool InvokeAction(ControllerContext controllerContext, string actionName) { 
           if (controllerContext == null) { 
               throw new ArgumentNullException("controllerContext"); 
           } 
           if (String.IsNullOrEmpty(actionName)) { 
               throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName"); 
           } 
 
           ControllerDescriptor controllerDescriptor = GetControllerDescriptor(controllerContext); 
           ActionDescriptor actionDescriptor = FindAction(controllerContext, controllerDescriptor, actionName); 
           if (actionDescriptor != null) { 
               FilterInfo filterInfo = GetFilters(controllerContext, actionDescriptor); 
 
               try { 
                   AuthorizationContext authContext = InvokeAuthorizationFilters(controllerContext, filterInfo.AuthorizationFilters, actionDescriptor); 
                   if (authContext.Result != null) { 
                       // the auth filter signaled that we should let it short-circuit the request  
                       InvokeActionResult(controllerContext, authContext.Result); 
                   } 
                   else { 
                       if (controllerContext.Controller.ValidateRequest) { 
                           ValidateRequest(controllerContext); 
                       } 
 
                       IDictionary<string, object> parameters = GetParameterValues(controllerContext, actionDescriptor); 
                       ActionExecutedContext postActionContext = InvokeActionMethodWithFilters(controllerContext, filterInfo.ActionFilters, actionDescriptor, parameters); 
                       InvokeActionResultWithFilters(controllerContext, filterInfo.ResultFilters, postActionContext.Result); 
                   } 
               } 
               catch (ThreadAbortException) { 
                   // This type of exception occurs as a result of Response.Redirect(), but we special-case so that  
                   // the filters don't see this as an error.  
                   throw; 
               } 
               catch (Exception ex) { 
                   // something blew up, so execute the exception filters  
                   ExceptionContext exceptionContext = InvokeExceptionFilters(controllerContext, filterInfo.ExceptionFilters, ex); 
                   if (!exceptionContext.ExceptionHandled) { 
                       throw; 
                   } 
                   InvokeActionResult(controllerContext, exceptionContext.Result); 
               } 
 
               return true; 
           } 
 
           // notify cont

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,