Пример #1
0
        /// <summary>
        /// 获取GET提交
        /// </summary>
        /// <param name="html">模板html</param>
        /// <returns></returns>
        public string GetRequest(string html)
        {
            string          pattern = @"\{\$GetRequest\([a-z0-9]*\)\$\}";//{$GetRequest(变量名)$}
            string          url     = rawurl.ToLower();
            string          query   = url.Contains("?") ? url.Split('?')[1] : "";
            MatchCollection matchs  = Regex.Matches(html, pattern, RegexOptions.IgnoreCase);

            for (int i = 0; i < matchs.Count; i++)
            {
                MatchCollection Smallmatchs = Regex.Matches(matchs[i].ToString(), pattern, RegexOptions.IgnoreCase);
                foreach (Match Smallmatch in Smallmatchs)
                {
                    string requesttxt = (Smallmatch.ToString().Replace(@"{$GetRequest(", "").Replace(@")$}", "") ?? "").ToLower();//变量名
                    string result     = "";
                    try
                    {
                        //从query中取值
                        result = StrHelper.GetValFromUrl(url, requesttxt);
                        //如为空,则检测是否为路由页面 /Shop/1  /Item/1
                        if (string.IsNullOrEmpty(result) && (requesttxt.Equals("id") || requesttxt.Equals("itemid")))
                        {
                            result = GetIDVal(url);
                        }
                        // /class_1/default
                        if (string.IsNullOrEmpty(result) && requesttxt.Equals("nodeid"))
                        {
                            result = Regex.Split(url, Regex.Escape("class_"))[1].Split('/')[0];
                        }
                        result = SafeValue(result);
                        //ZLLog.L(url + "|" + result + "|" + Smallmatchs[0].Value);
                    }
                    catch (Exception ex) { ZLLog.L(Model.ZLEnum.Log.exception, ex.Message); }
                    result = HttpUtility.HtmlEncode(result);
                    if (!string.IsNullOrEmpty(result) && SafeSC.CheckData(result))
                    {
                        result = ""; ZLLog.L(ZLEnum.Log.safe, "GetRequest:" + result);
                    }
                    html = html.Replace(Smallmatch.ToString(), result);
                }
            }
            return(html);
        }