Exemple #1
0
        public override IHttpResult GetActionResult()
        {
            string url = Request.Url;

            bool isPost = Request.Method == ConstHelper.POST;

            //禁止访问
            var flist = WebConfig.ForbiddenAccessList;

            if (flist.Count > 0)
            {
                foreach (var item in flist)
                {
                    if (url.IndexOf(item.ToUpper(), StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        return(new HttpContentResult("o_o,当前内容禁止访问!", System.Net.HttpStatusCode.Forbidden));
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(url, item))
                    {
                        return(new HttpContentResult("o_o,当前内容禁止访问!", System.Net.HttpStatusCode.Forbidden));
                    }
                }
            }

            if (url == "/")
            {
                url = "/index.html";
            }

            var filePath = Server.MapPath(url);

            if (StaticResourcesCache.Exists(filePath))
            {
                if (StaticResourcesCache.IsBigFile(filePath))
                {
                    return(new HttpBigDataResult(filePath));
                }
                else
                {
                    return(new HttpFileResult(filePath, IsStaticsCached));
                }
            }
            return(new HttpContentResult("o_o,找不到任何内容", System.Net.HttpStatusCode.NotFound));
        }
Exemple #2
0
        /// <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));
        }