昨天我写东西的时候遇到了一个问题,我当时为了省事就把4万多条记录一下都加载到了DropDownList控件上,增加操作没有问题,当修改的时候,出现了超出最大的要求长度的错误,我当时很纳闷,也不知道什么原因,错误好似下图:
在网上找了很久的数据,终于有了解决办法,我就把解决方法写出来,同大家分享。
1、如果使用 GridView 就要开启它的分页功能,将数据做分页之后即可解决。
2、maxRequestLength这个限制是ASP.NET为了要预防可能的「拒绝服务」攻击(Denial of Service attacks), 要解除这个限制,可在 Web.config 档案中的段落中,覆写应用程序 maxRequestLength 的值, 例如,下列的 Web.config 设定会允许最大 10 MB 的档案上传:
<System.Web>
<httpRuntime maxRequestLength="10240" />
</System.Web> |
不过,只要 POST 请求的内容(例如上传档案)超过 Web.config 的 maxRequestLength 设定,还是会收到
错误讯息。
3、在 Global.asax 档案中建立错误处理程序的程序代码:
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Configuration" %>
<script runat="server">
void Application_BeginRequest(object sender, EventArgs e)
{
HttpRuntimeSection section = (HttpRuntimeSection)ConfigurationManager.GetSection
("system.web/httpRuntime");
int maxFileSize = section.MaxRequestLength*1024;
if (Request.ContentLength > maxFileSize)
{
Response.Redirect("~/FileTooLarge.aspx");
}
}
</script> |
|