public static UrlEncode ( this value ) : string | ||
value | this | |
return | string |
/// <summary> /// url의 파라미터 값을 urlEncode /// </summary> /// <param name="url"></param> /// <returns></returns> public static string ParamUrlEncode(string url) { if (url.IndexOf("?") < 0) { return(url); } string[] param = GetParams(url); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); foreach (string pr in param) { string[] p = StringTool.Split(pr, '='); if (p.Length < 2) { continue; } if (string.IsNullOrEmpty(p[0])) { continue; } stringBuilder.AppendFormat("{0}={1}&", p[0], AntiXssTool.UrlEncode((p.Length > 1) ? p[1] : string.Empty)); } return(stringBuilder.ToString()); }
/// <summary> /// url의 파람값들을 collection 값에 있는 파람값들로 교체한다. /// </summary> /// <param name="url"></param> /// <param name="cols"></param> /// <param name="isEnc">UrlEncode 여부</param> /// <returns></returns> public static string ReplaceParamValue(string url, NameValueCollection cols, bool isEnc) { if (url.IndexOf("?") < 0) { return(url); } var ps = GetParam(url); url = GetUri(url); for (int i = 0; i < ps.Count; i++) { foreach (string ckey in cols.Keys) { if (string.IsNullOrEmpty(ckey)) { continue; } if (ps.GetKey(i).ToUpper().Equals(ckey.ToUpper())) { ps[ps.GetKey(i)] = cols[ckey]; break; } } } var p = new StringBuilder(); foreach (string k in ps.Keys) { p.AppendFormat("{0}={1}&", k, isEnc ? AntiXssTool.UrlEncode(ps[k]) : ps[k]); } return(UrlParamConcat(url, p.ToString())); }