首页 > 代码库 > Asp.net QueryString批量插入和更新
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(); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。