xuxiaoshuan

今天在页面上提交数据的时候出现这个异常:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

原来是微软对asp.net表单域的默认长度限制为1000,而我要上传的数据已经超过一千条。

 

问题:现在asp.net request 表单域的默认长度是1000,如果是超过一千 就会出错,或者request.form取不到1000以后的表单数据。

测试代码:

复制代码
<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<%
Response.Write(Request.Params.AllKeys.Length);
Response.Write("<br />");
for (int i = 0; i < 3000; i++)
{
Response.Write(string.Format("<input type=\'text\' name=\'txt{0}\' value=\'{0}\'/>",i));
if (i% 5 == 0)
{
Response.Write("<br />");
}
}
%>
<input type="submit" value="提交" />
</form>
</body>
</html>
复制代码

点提交会有如下图的错误(1、对象的当前状态使该操作无效;2、URL编码窗体数据无效):

解决办法:

在Web.config的appSettings加入如下配置:

    <appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="5000" />
</appSettings>


再次提交就不会出错,而且能取得所有表单的信息。

参考:

http://blogs.msdn.com/b/paulking/archive/2012/01/16/using-an-http-module-to-assist-in-adjusting-the-value-of-aspnet-maxhttpcollectionkeys-imposed-by-ms11-100.aspx

 

 转:http://www.cnblogs.com/tangruixin/archive/2012/03/06/2381687.html

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-06-30
  • 2022-01-25
  • 2022-02-16
  • 2022-12-23
  • 2021-10-10
  • 2021-10-01
猜你喜欢
  • 2021-07-09
  • 2022-02-08
  • 2022-02-20
  • 2022-12-23
相关资源
相似解决方案