private async Task ExecuteMvc(HttpContext context) { var controllerContext = new ControllerContext(context); IControllerBulider controllerBuilder = new ControllerBuilder(controllerContext); try { var controller = controllerBuilder.ControllerBuild(); await controller.Execute(); // CookieCollection对Cookie的处理有一个bug, // 当设置多个cookie的时候,Response的headers只有一个Set-Cookie // 且多个cookie的值都在这个Set-Cookie中 // 所以我们需要自己对cookie进行处理 CookieFix(context.Response); controllerBuilder.ControllerRelease(); } catch (NotFoundUrlException) { // not found case //var actionInvoker = new ActionInvokeProvider().GetActionInvoker(); //actionInvoker.InvokeAction(controllerContext); //var path = Path.Combine(ViewPath.Path, "Shared", NotFoundUrlView.NotFoundViewName+ ".html"); //if(!File.Exists(path)) //{ // path = Path.Combine(ViewPath.Path, "Shared", NotFoundUrlView.NotFoundViewName + ".htm"); //} if (!CheckFileExists(NotFoundUrlView.NotFoundViewName, ".html", out var path)) { if (!CheckFileExists(NotFoundUrlView.NotFoundViewName, ".htm", out path)) { if (!CheckFileExists(NotFoundUrlView.NotFoundViewName, ".cshtml", out path)) { context.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } } } var buffer = Encoding.UTF8.GetBytes(File.ReadAllText(path)); context.Response.ContentType = "text/html"; context.Response.StatusCode = (int)HttpStatusCode.NotFound; context.Response.ResponseStream.Write(buffer, 0, buffer.Length); } }