如果你在asp.net 的站点的网址后面加上这么一串?__VIEWSTATE=YY

 例如:

你将得到一个类似这样的报错页面:

 

 Asp.net 小技巧 1 :解决__VIEWSTATE bug

要解决这个问题其实也很简单:

在后台页面加上这么一段代码 就OK了

 

 

代码
 1   protected override void OnInitComplete(EventArgs e)
 2     {
 3         base.OnInitComplete(e);
 4         if (Request.QueryString.AllKeys.Contains("__VIEWSTATE"))
 5         {
 6             PropertyInfo info = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
 7             if (info != null)
 8             {
 9                 info.SetValue(Request.QueryString, falsenull);
10                 Request.QueryString.Remove("__VIEWSTATE");
11                 info.SetValue(Request.QueryString, truenull);
12             }
13         }
14     }

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2021-07-14
  • 2021-10-17
  • 2022-01-08
  • 2022-12-23
  • 2021-10-09
猜你喜欢
  • 2022-12-23
  • 2022-02-23
  • 2021-04-19
  • 2021-10-27
  • 2021-10-04
  • 2022-12-23
相关资源
相似解决方案