/// <summary> /// 构建mvc容器 /// </summary> /// <param name="root">根目录</param> /// <param name="port">监听端口</param> /// <param name="isStaticsCached">是否启用静态缓存</param> /// <param name="isZiped">是压启用内容压缩</param> /// <param name="bufferSize">http处理数据缓存大小</param> /// <param name="count">http连接数上限</param> public SAEAMvcApplication(string root = "/wwwroot/", int port = 39654, bool isStaticsCached = true, bool isZiped = false, int bufferSize = 1024 * 10, int count = 100) { var mvcInvoker = new MvcInvoker(AreaCollection.RouteTable); webHost = new WebHost(mvcInvoker, root, port, isStaticsCached, isZiped, bufferSize, count); }
/// <summary> /// 根据地址路由到目标并返回执行结果 /// </summary> /// <returns></returns> public override IHttpResult GetActionResult() { string url = Request.Url; bool isPost = Request.Method == ConstHelper.POST; //禁止访问 var flist = WebConfig.ForbiddenAccessList; if (flist.Any()) { foreach (var item in flist) { if (url.IndexOf(item, StringComparison.OrdinalIgnoreCase) >= 0) { return(new ContentResult("o_o,当前内容禁止访问!url:" + url, System.Net.HttpStatusCode.Forbidden)); } if (System.Text.RegularExpressions.Regex.IsMatch(url, item, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { return(new ContentResult("o_o,当前内容禁止访问!url:" + url, System.Net.HttpStatusCode.Forbidden)); } } } var arr = url.Split("/", StringSplitOptions.RemoveEmptyEntries); var filePath = string.Empty; NameValueCollection nameValues; switch (arr.Length) { case 0: filePath = Server.MapPath(WebConfig.HomePage); if (string.IsNullOrWhiteSpace(filePath)) { new ContentResult($"o_o,找不到任何内容 url:{url} filePath:{filePath}", System.Net.HttpStatusCode.NotFound); } if (StaticResourcesCache.Exists(filePath)) { if (StaticResourcesCache.IsBigFile(filePath)) { return(new BigDataResult(filePath)); } else { return(new FileResult(filePath, IsStaticsCached)); } } else { if (RouteTable.Types == null) { return(new ContentResult("o_o,找不到任何路由信息!url:" + url, System.Net.HttpStatusCode.NotFound)); } var d = RouteTable.Types.Where(b => (string.Compare(b.Name, WebConfig.DefaultRoute.Name, true) == 0 || string.Compare(b.Name, WebConfig.DefaultRoute.Name + ConstHelper.CONTROLLERNAME, true) == 0)).FirstOrDefault(); nameValues = Request.Parmas.ToNameValueCollection(); return(MvcInvoker.InvokeResult(_routeTable, d, WebConfig.DefaultRoute.Value, nameValues, isPost)); } case 1: filePath = Server.MapPath(url); if (StaticResourcesCache.Exists(filePath)) { if (StaticResourcesCache.IsBigFile(filePath)) { return(new BigDataResult(filePath)); } else { return(new FileResult(filePath, IsStaticsCached)); } } break; default: var controllerName = arr[arr.Length - 2]; if (RouteTable.Types != null && RouteTable.Types.Any()) { var first = RouteTable.Types.Where(b => string.Compare(b.Name, controllerName + ConstHelper.CONTROLLERNAME, true) == 0).FirstOrDefault(); if (first != null) { nameValues = Request.Parmas.ToNameValueCollection(); return(MvcInvoker.InvokeResult(_routeTable, first, arr[arr.Length - 1], nameValues, isPost)); } } filePath = Server.MapPath(url); if (StaticResourcesCache.Exists(filePath)) { if (StaticResourcesCache.IsBigFile(filePath)) { return(new BigDataResult(filePath)); } else { return(new FileResult(filePath, IsStaticsCached)); } } break; } return(new ContentResult("o_o,找不到任何内容 url:" + url, System.Net.HttpStatusCode.NotFound)); }