internal static void ExecuteAction(HttpContext context, InvokeInfo vkInfo) { if( context == null ) throw new ArgumentNullException("context"); if( vkInfo == null ) throw new ArgumentNullException("vkInfo"); // 验证请求是否允许访问(身份验证) AuthorizeAttribute authorize = vkInfo.GetAuthorize(); if( authorize != null ) { if( authorize.AuthenticateRequest(context) == false ) ExceptionHelper.Throw403Exception(context); } // 调用方法 object result = ExecuteActionInternal(context, vkInfo); // 设置OutputCache OutputCacheAttribute outputCache = vkInfo.GetOutputCacheSetting(); if( outputCache != null ) outputCache.SetResponseCache(context); // 处理方法的返回结果 IActionResult executeResult = result as IActionResult; if( executeResult != null ) { executeResult.Ouput(context); } else { if( result != null ) { // 普通类型结果 context.Response.ContentType = "text/plain"; context.Response.Write(result.ToString()); } } }
public static ActionHandler CreateHandler(InvokeInfo vkInfo) { SessionMode mode = vkInfo.GetSessionMode(); if( mode == SessionMode.NotSupport ) return new ActionHandler { InvokeInfo = vkInfo }; else if( mode == SessionMode.ReadOnly ) return new ReadOnlySessionActionHandler { InvokeInfo = vkInfo }; else return new RequiresSessionActionHandler { InvokeInfo = vkInfo }; }
internal static object ExecuteActionInternal(HttpContext context, InvokeInfo info) { // 准备要传给调用方法的参数 object[] parameters = GetActionCallParameters(context, info.Action); // 调用方法 if( info.Action.HasReturn ) return info.Action.MethodInfo.Invoke(info.Instance, parameters); else { info.Action.MethodInfo.Invoke(info.Instance, parameters); return null; } }