装载当前页面的模板文档

        /// <summary>
        /// 装载当前页面的模板文档
        /// </summary>
        public virtual void LoadCurrentTemplate()
        {
            //是否是手机端网页
            string filePath = this.Request.Url.AbsolutePath;
            bool isMobi = isMobilePage(out filePath);     //处理后filePath为文件名(不含扩展名)  
            if (isMobi && LoginState.Accounts.IsLogin)
                LoginState.Accounts.Refresh(LoginState.Accounts.CurrentUser);            
            //取模板对象
            this.TmBank = isMobi ?
                WeiSha.Common.Template.ForMobile.SetCurrent(this.Organ.Org_TemplateMobi)
                : WeiSha.Common.Template.ForWeb.SetCurrent(this.Organ.Org_Template);
            if (TmBank == null) throw new Exception("没有任何模板库可用!");
            //是否是公共页面
            if (TmBank.Config.Public == null) throw new Exception("未找到公共模板库!");
            bool isPublic = TmBank.Config.Public.PageExists(filePath);
            if (isPublic) TmBank = TmBank.Config.Public;
            //当前模板的所在路径
            string tmFile = TmBank.Path.Physics + filePath + ".htm";
            //装载模板
            this.Document = null;
            if (!System.IO.File.Exists(tmFile))
            {
                tmFile = TmBank.Config.Default.Path.Physics + filePath + ".htm";
                if (!System.IO.File.Exists(tmFile)) tmFile = TmBank.Config.Public.Path.Physics + "Notfound.htm";                             
            }
            this.Document = TemplateDocument.FromFileCache(tmFile, Encoding.UTF8, this.DocumentConfig);
            //this.Document = new TemplateDocument(tmFile, Encoding.UTF8, this.DocumentConfig);   //不采用缓存 
        }

 

posted @ 2019-08-13 15:45  DarJeely  阅读(216)  评论(0编辑  收藏  举报