.Net HttpContext.Current.Request 常用处理方案

1、清理request的请求数据

PropertyInfo isreadonly =typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
// make collection editable
isreadonly.SetValue(HttpContext.Current.Request.QueryString, false, null);

foreach (var key in HttpContext.Current.Request.QueryString.AllKeys)
{
HttpContext.Current.Request.QueryString.Set(key, HttpContext.Current.Request.QueryString[key].Split(',').First());
//HttpContext.Current.Request.QueryString[key] = HttpContext.Current.Request.QueryString[key].Split(',').First();
}
isreadonly.SetValue(HttpContext.Current.Request.QueryString, true, null);

原文地址:https://www.cnblogs.com/ransom/p/8126100.html