/// <summary> /// 处理找不到Action /// </summary> /// <param name="route">路由</param> /// <param name="requestContext">上下文</param> private void ProcessActionNotFound(string route, RequestContext requestContext) { var exception = new ApiNotExistException(route); var exceptionContext = new ExceptionContext(requestContext, exception); foreach (var filter in this.GlobalFilter.ExceptionFilters) { filter.OnException(exceptionContext); if (exceptionContext.ExceptionHandled == true) { break; } } var result = exceptionContext.Result != null ? exceptionContext.Result : new ErrorResult { Status = 404, Errors = exception.Message }; result.ExecuteResult(requestContext); }
/// <summary> /// 收到Http请求 /// </summary> /// <param name="request">请求对象</param> /// <param name="response">回复对象</param> protected override void OnHttpRequest(HttpRequest request, HttpResponse response) { var route = request.Url.AbsolutePath; var action = this.httpActionList.TryGet(route); var requestContext = new RequestContext(request, response); if (action == null) { var exception = new ApiNotExistException(route); var exceptionContext = new ExceptionContext(requestContext, exception); foreach (var filter in this.GlobalFilter.ExceptionFilters) { filter.OnException(exceptionContext); if (exceptionContext.ExceptionHandled == true) break; } var result = exceptionContext.Result == null ? new ErrorResult { Status = 404, Errors = exception.Message } : exceptionContext.Result; result.ExecuteResult(requestContext); } else { var controller = this.DependencyResolver.GetService(action.DeclaringService) as HttpController; var actionContext = new ActionContext(requestContext, action); controller.Server = this; ((IHttpController)controller).Execute(actionContext); } }
/// <summary> /// 处理http请求 /// </summary> /// <param name="requestContext">请求上下文</param> private void ProcessRequest(RequestContext requestContext) { var route = requestContext.Request.Url.AbsolutePath; var action = this.httpActionList.TryGet(requestContext.Request); if (action == null) { var exception = new ApiNotExistException(route); var exceptionContext = new ExceptionContext(requestContext, exception); foreach (var filter in this.GlobalFilter.ExceptionFilters) { filter.OnException(exceptionContext); if (exceptionContext.ExceptionHandled == true) break; } var result = exceptionContext.Result != null ? exceptionContext.Result : new ErrorResult { Status = 404, Errors = exception.Message }; result.ExecuteResult(requestContext); } else { var controller = this.DependencyResolver.GetService(action.DeclaringService) as HttpController; var actionContext = new ActionContext(requestContext, action); controller.Server = this; ((IHttpController)controller).Execute(actionContext); // 释放资源 this.DependencyResolver.TerminateService(controller); } }
/// <summary> /// 处理找不到Action /// </summary> /// <param name="route">路由</param> /// <param name="requestContext">上下文</param> private void ProcessActionNotFound(string route, RequestContext requestContext) { var exception = new ApiNotExistException(route); var exceptionContext = new ExceptionContext(requestContext, exception); foreach (var filter in this.GlobalFilter.ExceptionFilters) { filter.OnException(exceptionContext); if (exceptionContext.ExceptionHandled == true) break; } var result = exceptionContext.Result != null ? exceptionContext.Result : new ErrorResult { Status = 404, Errors = exception.Message }; result.ExecuteResult(requestContext); }