.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);

posted @ 2017-12-27 15:43  ransom  阅读(3742)  评论(0编辑  收藏  举报