Asp.net QueryString批量插入和更新
public static string InsertOrUpdateQueryString(string[] keys, string[] values) { return InsertOrUpdateQueryString(System.Web.HttpContext.Current.Request, keys, values); } public static string InsertOrUpdateQueryString(System.Web.HttpRequest request, string[] keys, string[] values) { string keyValue; string keyCurrent; System.Text.StringBuilder pathBuilder = new System.Text.StringBuilder(request.Path); pathBuilder.Append("?"); int handedCount = 0; if (request.QueryString.HasKeys()) { for (var i = 0; i < request.QueryString.AllKeys.Length;i++ ) { keyValue = request.QueryString.AllKeys[i]; if (string.IsNullOrEmpty(keyValue)) { continue; } if (Array.IndexOf<string>(keys, keyValue) != -1) { continue; } keyCurrent = request.QueryString[i]; if (string.IsNullOrEmpty(keyValue)) { continue; } if (i != 0) { pathBuilder.AppendFormat("&{0}={1}", keyValue, keyCurrent); } else { pathBuilder.AppendFormat("{0}={1}", keyValue, keyCurrent); } handedCount++; } } for (var i = 0; i < keys.Length; i++) { keyValue = keys[i]; keyCurrent = values[i]; if (string.IsNullOrEmpty(keyValue) || string.IsNullOrEmpty(keyCurrent)) { continue; } if (handedCount++ != 0) { pathBuilder.AppendFormat("&{0}={1}", keyValue,keyCurrent); } else { pathBuilder.AppendFormat("{0}={1}", keyValue, keyCurrent); } } return pathBuilder.ToString(); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。