Esempio n. 1
0
        /// <summary>
        /// URL拼接
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="urlparameter">参数,用分号隔开(';')</param>
        /// <param name="Path">路径</param>
        /// <returns></returns>
        public static string UrlConverter(string filename, string urlparameter, string Path, bool IsUrlRewriter = true)
        {
            string        result  = string.Empty;        //返回拼接结果
            StringBuilder Urlpar  = new StringBuilder(); //URL参数连接
            string        Urlpars = string.Empty;        //URL参数
            StringBuilder query   = new StringBuilder();

            string[] ar = new string[] { "usage", "metal", "style", "cash", "sort", "od", "size", "weight" };
            if (!string.IsNullOrEmpty(urlparameter))
            {
                string[] Par = urlparameter.Split(';');
                for (int i = 0; i < Par.Length; i++)
                {
                    if (Par[i].Trim() != string.Empty)
                    {
                        if (Par[i].IndexOf('=') > -1)
                        {
                            string[] ParVa = Par[i].Split('=');
                            string   key   = ParVa[0].ToLower();
                            if (key == "nodeid")
                            {
                                Urlpar.Append("-c" + ParVa[1]);
                            }
                            else if (key.In(ar))
                            {
                                if (query.ToString().IndexOf("?") == -1)
                                {
                                    query.Append("?" + ParVa[0] + "=" + ParVa[1]);
                                }
                                else
                                {
                                    query.Append("&" + ParVa[0] + "=" + ParVa[1]);
                                }
                            }
                            else
                            {
                                Urlpar.Append("-" + ParVa[1]);
                            }
                        }
                    }
                }
                Urlpars = urlparameter.Replace(";", "&");
            }

            string DummyPath = "/" + Path;
            string UrlModel  = ConfigManager.GetString("UrlModel");
            string UrlExt    = ConfigManager.GetString("UrlExt");

            if (UrlModel == "0" || !IsUrlRewriter)
            {
                //动态
                if (!string.IsNullOrEmpty(Urlpars))
                {
                    result = DummyPath + filename + ".aspx?" + Urlpars;
                }
                else
                {
                    result = DummyPath + filename + ".aspx";
                }
            }
            else
            {
                //伪静态
                if (!string.IsNullOrEmpty(Urlpar.ToString()))
                {
                    result = DummyPath + filename + Urlpar.ToString() + UrlExt + query;
                }
                else
                {
                    result = DummyPath + filename + UrlExt;
                }
            }
            return(result);
        }