Ejemplo n.º 1
0
        public static IHttpHandler CreateHandler(InvokeInfo vkInfo)
        {
            // 对异步的支持,只限于返回值类型是 Task 或者 Task<T>
            // 所以这里只判断是不是Task类型的返回值,如果是,则表示是一个异步Action

            if (vkInfo.Action.MethodInfo.IsTaskMethod())
            {
                return(TaskAsyncActionHandler.CreateHandler(vkInfo));
            }

            else
            {
                return(ActionHandler.CreateHandler(vkInfo));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 输出结果
        /// </summary>
        /// <param name="context"></param>
        public void Ouput(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            context.Response.Cache.SetCacheability(HttpCacheability.Public);


            if (MaxAge > 0)
            {
                context.Response.Cache.AppendCacheExtension("max-age=" + MaxAge.ToString());
            }

            // LastModified 可以不设置,那么就是默认值:DateTime.MinValue
            // 判断的意思是:如果设置了LastModified,就调用 SetLastModified
            if (LastModified.Year > 2000)
            {
                context.Response.Cache.SetLastModified(LastModified);
            }

            if (string.IsNullOrEmpty(ETag) == false)
            {
                context.Response.Cache.SetETag(ETag);
            }


            // 找回与当前请求有关的ActionExecutor实例。
            ActionHandler handler = context.Handler as ActionHandler;

            if (handler == null)
            {
                throw new InvalidOperationException("HttpCacheResult只能与ActionHandler一起配合使用。");
            }

            // 输出内部对象
            handler.ActionExecutor.ExecuteProcessResult(this.Result);
        }
Ejemplo n.º 3
0
        internal void ProcessRequest(HttpContext context, ActionHandler handler)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            this.HttpContext = context;
            this.Handler     = handler;
            this.InvokeInfo  = handler.InvokeInfo;

            // 设置 BaseController 的相关属性
            SetController();

            // 进入请求处理阶段
            ExecuteBeginRequest();

            // 安全检查
            ExecuteSecurityCheck();

            // 授权检查
            ExecuteAuthorizeRequest();

            // 执行 Action
            object actionResult = ExecuteAction();

            // 设置输出缓存
            SetOutputCache();

            // 处理方法的返回结果
            ExecuteProcessResult(actionResult);
        }