Пример #1
0
        public string getHtml(HttpRequest request, string virtualWebDir, string url, bool isMobile)
        {
            Config.systemVariables["webUrl"] = "http://" + request.Url();
            //            Config.systemVariables["webUrl"] = "http://" + PageContext.Current.Request.Url.Authority + Config.webPath;
            //Config.systemVariables["pageUrl"] = PageContext.Current.Request.Url.AbsoluteUri.ToString();// "http://" + PageContext.Current.Request.Url.Authority +""+ Config.webPath;
            _pageNo = 1;
            Regex        r            = new Regex(@"(?<=/)((.[^/]*)_((\d){1,5}))(." + BaseConfig.extension + ")", RegexOptions.IgnoreCase);
            string       newUrl       = r.Replace(url, new MatchEvaluator(_replaceUrl));
            PageTemplate pageTemplate = null;

            pageTemplate = new PageTemplate(newUrl, isMobile);
            pageTemplate.Build();
            //TemplateInfo info = TemplateClass.get(newUrl, isMobile);
            if (pageTemplate == null)
            {
                Page.ERR404("模板不存在");
            }
            else
            {
                /*
                 * if (info.u_type == 2)
                 * {
                 *  Helper.Sql.ExecuteNonQuery("update mainTable set clickCount=clickCount+1 where id=@id", new SqlParameter[]{
                 *  new SqlParameter("id",info.variable["id"])
                 * });
                 * }*/
                if (newUrl.IndexOf(".") > -1)
                {
                    string[] u = newUrl.Split('/');
                    _fileName = u[u.Length - 1].Replace("." + BaseConfig.extension, "");
                }
                else
                {
                    _fileName = "default";
                }

                pageTemplate.Variable.Add("_pageNo", _pageNo);
                pageTemplate.Variable.Add("_url", request.Url());
                pageTemplate.Variable.Add("_fileName", _fileName);
                string html = RazorEngine.Razor.Run(pageTemplate.TemplateId.ToString(), new object[] { Config.systemVariables, pageTemplate.Variable, pageTemplate.Parameter });

                SubDomains subDomains = new SubDomains();
                subDomains.isMobile = isMobile;
                subDomains.replaceUrl(ref html);
                return(html);
            }
            return(null);
        }