首页 > 技术文章 > .Net HttpContext.Current.Request 常用处理方案

ransom 2017-12-27 15:43 原文

 

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

推荐阅读