Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception Details: System.Web.HttpException: Maximum request length exceeded

Am trying to read data from an Excel file into an ADO.NET Dataset using the code below. In a windows Forms application it work, but in an asp.net application it fails.

 public static DataTable ArchiveData(string fileName)
{
    FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read);

    //Reading from a OpenXml Excel file (2007 format; *.xlsx)
    IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
    excelReader.IsFirstRowAsColumnNames = true;

    DataSet result = excelReader.AsDataSet();

    //Free resources (IExcelDataReader is IDisposable)
    excelReader.Close();
    return result.Tables["Archive data"];
}

Stack Trace:

[HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +8793522
   System.Web.HttpRequest.GetMultipartContent() +62
   System.Web.HttpRequest.FillInFormCollection() +236
   System.Web.HttpRequest.get_Form() +68
   System.Web.HttpRequest.get_HasForm() +8745879
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97
   System.Web.UI.Page.DeterminePostBackMode() +63
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +133

OR is there a better way of reading an Excel file from a client machine into an ADO.NET DataTable in ASP.NET

like image 833
StackTrace Avatar asked Mar 05 '13 07:03

StackTrace


People also ask

How do you handle Maximum request length exceeded?

The default maximum filesize is 4MB - this is done to prevent denial of service attacks in which an attacker submitted one or more huge files which overwhelmed server resources. If a user uploads a file larger than 4MB, they'll get an error message: "Maximum request length exceeded." Server Error in '/' Application.

How do I change maxRequestLength in IIS?

Locate the following line: <httpRuntime maxRequestLength="100000" executionTimeout="1800" /> . Change the maxRequestLength to a value (in KB) equal to the maximum object size configured in vFire. The maximum value supported for web. config is 2147483647.


1 Answers

Add following tag in your web.config file and check if it works

<httpRuntime maxRequestLength="350000" enableVersionHeader="false" maxQueryStringLength="3584" executionTimeout="600"/>
like image 197
K D Avatar answered Oct 02 '22 01:10

K D