internal async Task ProcessRequestAsync(HttpContext context, TaskAsyncActionHandler 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(); // 在异步执行前,先保存当前同步上下文的实例,供异步完成后执行切换调用。 SynchronizationContext syncContxt = SynchronizationContext.Current; // 进入请求处理阶段 BeginRequest(); // 安全检查 SecurityCheck(); // 授权检查 AuthorizeRequest(); //this.HttpContext.WriteHeader("ProcessRequestAsync-before-await"); // 执行 Action object actionResult = await ExecuteActionAsync(); //this.HttpContext.WriteHeader("ProcessRequestAsync-after-await"); // 切换到原先的上下文环境,执行余下操作 syncContxt.Send(x => { //System.Runtime.Remoting.Messaging.CallContext.HostContext = (HttpContext)x; // 设置输出缓存 SetOutputCache(); // 处理方法的返回结果 //this.HttpContext.WriteHeader("call OutputResult()"); OutputResult(actionResult); }, this.HttpContext); }
public static IHttpHandler CreateHandler(InvokeInfo vkInfo) { // MyMMC对异步的支持,只限于返回值类型是 Task 或者 Task<T> // 所以这里只判断是不是Task类型的返回值,如果是,则表示是一个异步Action if (vkInfo.Action.MethodInfo.IsTaskMethod()) { return(TaskAsyncActionHandler.CreateHandler(vkInfo)); } else { return(ActionHandler.CreateHandler(vkInfo)); } }
internal async Task ProcessRequestAsync(HttpContext context, TaskAsyncActionHandler 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(); // 在异步执行前,先保存当前同步上下文的实例,供异步完成后执行切换调用。 SynchronizationContext syncContxt = SynchronizationContext.Current; // 进入请求处理阶段 BeginRequest(); // 安全检查 SecurityCheck(); // 授权检查 AuthorizeRequest(); //this.HttpContext.WriteHeader("ProcessRequestAsync-before-await"); // 执行 Action object actionResult = await ExecuteActionAsync(); //this.HttpContext.WriteHeader("ProcessRequestAsync-after-await"); // 切换到原先的上下文环境,执行余下操作 syncContxt.Send(x => { //System.Runtime.Remoting.Messaging.CallContext.HostContext = (HttpContext)x; // 设置输出缓存 SetOutputCache(); // 处理方法的返回结果 //this.HttpContext.WriteHeader("call OutputResult()"); OutputResult(actionResult); }, this.HttpContext); }