转义URL地址,并把xxx.aspx?id={0}&thename={1}|id|thename - ConvertDataBaseUrl

2017-02-26 20:29:49  访问(2302) 赞(0) 踩(0)


        /// <summary>
        /// 转义URL地址,并把xxx.aspx?id={0}&thename={1}|id|thename - ConvertDataBaseUrl
        /// </summary>
        /// <param name="phyPath"></param>
        /// <param name="str"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public string ConvertDataBaseUrl(string phyPath, string str, BaseModel model)
        {
            if (str == null)
                return "";

            if (str.StartsWith("~/") || str.StartsWith("-/"))
                str = phyPath + str.Substring(1);


            string[] sArray = str.Split(new char[] { '|' });

            if (sArray == null)
                return "";

            int iLen = sArray.Length;

            if (iLen == 0)
                return "";

            string theResult = sArray[0];

            if (theResult == null || theResult.Length == 0)
                return "";

            List<string> theList = new List<string>();
            string strItem = null;

            for (int i = 1; i < iLen; ++i)
            {
                if (sArray[i] == null || sArray[i].Length == 0)
                    continue;


                strItem = model.GetPropertyStrValue(sArray[i]);


                if (strItem == null)
                    strItem = "";
                else
                    strItem = HttpContext.Current.Server.UrlEncode(strItem);
             
                theList.Add(strItem);
            }


            int iListCount = theList.Count;

            if (iListCount == 0)
                return theResult;

            string[] strArray = new string[iListCount];

            for (int i = 0; i < iListCount; ++i)
            {
                strArray[i] = theList[i];
            }

            theResult = string.Format(theResult, strArray);

            return theResult;
        }


标签:转义URL地址,并把xxx.aspx?id={0}&thename={1}|id|thename - ConvertDataBaseUrl 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)