コード例 #1
0
        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            string actionName = requestContext.RouteData.GetRequiredString("action");
            string key        = _namingConventions.BuildKeyFromControllerAndAction(controllerName, actionName);

            ActionController actionInstance = null;

            try
            {
                Type t;
                if (_actionTypes.TryGetValue(key, out t))
                {
                    actionInstance = _createController(t) as ActionController;
                }
                else
                {
                    return(base.CreateController(requestContext, controllerName));
                }
            }
            catch (Exception ex)
            {
                throw new HttpException(404, "Controller not found", ex);
            }

            if (actionInstance == null)
            {
                throw new HttpException(404, "Controller not found");
            }

            actionInstance.NamingConventions = _namingConventions;

            return(actionInstance);
        }