Exemplo n.º 1
0
 /// <summary>
 /// 获取绑定域名的频道分类目录名
 /// </summary>
 /// <param name="webPath">网站安装目录</param>
 /// <param name="requestPath">当前页面,包含目录</param>
 /// <param name="requestDomain">当前的域名(含端口号)</param>
 /// <returns>String</returns>
 private string GetDomainPath(string webPath, string requestPath, string requestDomain)
 {
     //获取绑定域名的目录
     if (SiteDomains.GetSiteDomains().CategoryDirs.ContainsValue(requestDomain))
     {
         return(SiteDomains.GetSiteDomains().Domains[requestDomain]);
     }
     return(string.Empty);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 获取虚拟目录的频道分类目录名
        /// </summary>
        /// <param name="webPath">网站安装目录</param>
        /// <param name="requestPath">当前页面,包含目录</param>
        /// <param name="requestDomain">当前的域名(含端口号)</param>
        /// <returns>String</returns>
        private string GetCategoryPath(string webPath, string requestPath, string requestDomain)
        {
            //获取URL的虚拟目录(除安装目录)
            string requestFirstPath = GetFirstPath(webPath, requestPath);

            if (requestFirstPath != string.Empty && SiteDomains.GetSiteDomains().CategoryDirs.ContainsKey(requestFirstPath))
            {
                return(requestFirstPath);
            }
            return(string.Empty);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 返回域名字典
        /// </summary>
        public static SiteDomains GetSiteDomains()
        {
            SiteDomains _cache = _Cache.Get <SiteDomains>(Vincent._DTcms.DTKeys.CACHE_SITE_HTTP_DOMAIN);

            lock (lockHelper)
            {
                if (_cache == null)
                {
                    _Cache.Insert(Vincent._DTcms.DTKeys.CACHE_SITE_HTTP_DOMAIN, new SiteDomains(), 10);
                    instance = _Cache.Get <SiteDomains>(Vincent._DTcms.DTKeys.CACHE_SITE_HTTP_DOMAIN);
                }
            }
            return(instance);
        }
Exemplo n.º 4
0
        ///// <summary>
        ///// 取得用户信息
        ///// </summary>
        //public Model.users GetUserInfo2()
        //{
        //    if (IsUserLogin())
        //    {
        //        _ModelUsers = HttpContext.Current.Session[Vincent._DTcms.DTKeys.SESSION_USER_INFO] as Model.users;
        //        if (_ModelUsers != null)
        //        {
        //            //为了能查询到最新的用户信息,必须查询最新的用户资料
        //            _ModelUsers = new BLL.users().GetModel(_ModelUsers.id);
        //            return _ModelUsers;
        //        }
        //    }
        //    return null;
        //}

        #endregion

        #region 辅助方法(私有)========================================
        /// <summary>
        /// 获取访问的频道分类目录(不含安装目录)
        /// </summary>
        private string GetFirstPath()
        {
            //string requestPath = HttpContext.Current.Request.CurrentExecutionFilePath.ToLower();//获得当前页面虚拟路径
            string requestPath = HttpContext.Current.Request.RawUrl.ToLower();
            int    indexNum    = config.webpath.Length; //安装目录长度

            //如果包含安装目录和aspx目录也要过滤掉
            if (requestPath.StartsWith(config.webpath + Vincent._DTcms.DTKeys.DIRECTORY_REWRITE_ASPX + "/"))
            {
                indexNum = (config.webpath + Vincent._DTcms.DTKeys.DIRECTORY_REWRITE_ASPX + "/").Length;
            }
            string requestFirstPath = requestPath.Substring(indexNum);

            if (requestFirstPath.IndexOf("/") > 0)
            {
                requestFirstPath = requestFirstPath.Substring(0, requestFirstPath.IndexOf("/"));
            }
            if (requestFirstPath != string.Empty && SiteDomains.GetSiteDomains().CategoryDirs.ContainsKey(requestFirstPath))
            {
                return(requestFirstPath);
            }
            return(string.Empty);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 返回URL重写统一链接地址
        /// </summary>
        public string linkurl(string _key, params object[] _params)
        {
            Hashtable ht = new BLL.url_rewrite().GetList();          //获得URL配置列表

            Model.url_rewrite model = ht[_key] as Model.url_rewrite; //查找指定的URL配置节点

            //如果不存在该节点则返回空字符串
            if (model == null)
            {
                return(string.Empty);
            }

            string requestDomain    = HttpContext.Current.Request.Url.Authority.ToLower(); //获得来源域名含端口号
            string requestFirstPath = GetFirstPath();                                      //获得二级目录(不含站点安装目录)
            string linkStartString  = string.Empty;                                        //链接前缀

            //检查是否与绑定的域名或者与默认频道分类的目录匹配
            if (SiteDomains.GetSiteDomains().CategoryDirs.ContainsValue(requestDomain))
            {
                linkStartString = "/";
            }

            else if (requestFirstPath == string.Empty || requestFirstPath == SiteDomains.GetSiteDomains().DefaultPath)
            {
                linkStartString = config.webpath;
            }
            else
            {
                linkStartString = config.webpath + requestFirstPath + "/";
            }
            //如果URL字典表达式不需要重写则直接返回
            if (model.url_rewrite_items.Count == 0)
            {
                //检查网站重写状态
                if (config.staticstatus > 0)
                {
                    if (_params.Length > 0)
                    {
                        return(linkStartString + GetUrlExtension(model.page, config.staticextension) + string.Format("{0}", _params));
                    }
                    else
                    {
                        return(linkStartString + GetUrlExtension(model.page, config.staticextension));
                    }
                }
                else
                {
                    if (_params.Length > 0)
                    {
                        return(linkStartString + model.page + string.Format("{0}", _params));
                    }
                    else
                    {
                        return(linkStartString + model.page);
                    }
                }
            }
            //否则检查该URL配置节点下的子节点
            foreach (Model.url_rewrite_item item in model.url_rewrite_items)
            {
                //如果参数个数匹配
                if (IsUrlMatch(item, _params))
                {
                    //检查网站重写状态
                    if (config.staticstatus > 0)
                    {
                        return(linkStartString + string.Format(GetUrlExtension(item.path, config.staticextension), _params));
                    }
                    else
                    {
                        string queryString = Regex.Replace(string.Format(item.path, _params), item.pattern, item.querystring, RegexOptions.None | RegexOptions.IgnoreCase);
                        if (queryString.Length > 0)
                        {
                            queryString = "?" + queryString;
                        }
                        return(linkStartString + model.page + queryString);
                    }
                }
            }

            return(string.Empty);
        }