You receive error messages when you try to upload a file to an ASP.NET Web page by using the FileUpload control in IIS 5.1 (910436)



The information in this article applies to:

  • Microsoft Internet Information Services version 5.1
  • Microsoft .NET Framework 2.0

SYMPTOMS

Consider the following scenario. A Web server is running Microsoft Internet Information Services (IIS) 5.1. A Microsoft ASP.NET Web page that is built on the Microsoft .NET Framework 2.0 is hosted on the Web server. You try to upload a file to the Web page by using the FileUpload control. In this scenario, you receive the following error messages:
The page cannot be displayed
Cannot find server or DNS Error

CAUSE

This problem occurs because the file size is larger than the size that is specified in the maxRequestLength attribute in the httpRuntime section of the Machine.config file.

RESOLUTION

This problem is fixed in IIS 6.0. IIS 6.0 is included with Microsoft Windows Server 2003.

WORKAROUND

To work around this problem, add code to the Application_Error event handler in the Global.asax file of the Web application to capture the error and redirect the user to a custom error page. The Application_Error method may appear similar to one of the following code examples.

C# code example

protected void Application_Error(Object sender, EventArgs e)
{
	// Code that runs when an unhandled error occurs.
	// Determine whether the request originates from the file upload Web page (FileUpload.aspx).
	if (Request.Path.EndsWith("FileUpload.aspx "))
	{
		
		// Obtain the error details.
		HttpException httpEx = Server.GetLastError() as HttpException;

		// Verify the expected error.
		if (httpEx.GetHttpCode() == 500 && httpEx.ErrorCode == -2147467259)
		{
			Server.ClearError();
			
			// Redirect the user to the custom error page (ErrorPage.aspx).
			HttpContext.Current.Response.Redirect("ErrorPage.aspx");		
		}
	}
}

Microsoft Visual Basic code example

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
 	' Code that runs when an unhandled error occurs.
 	' Determine whether the request originates from the file upload Web page (FileUpload.aspx).
	If (Request.Path.EndsWith("FileUpload.aspx")) Then
        
		' Obtain the error details.

        	Dim checkException As HttpException = CType(Server.GetLastError(), HttpException)

        	' Verify the expected error.
        	If  (checkException.GetHttpCode = 500 and checkException.ErrorCode = -2147467259) Then
            		
			Server.ClearError()
            		
			' Redirect the user to the custom error page (ErrorPage.aspx).
           		HttpContext.Current.Response.Redirect("ErrorPage.aspx")
       		End If
    	End If
        
End Sub

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

You can modify the 4 MB (4,096 KB) default size for uploads. To do this, add the following code to the System.Web section of the Web.config file for the Web application.
<httpRuntime maxRequestLength="10240"/>
Note The size for the maxRequestLength attribute is in KB.

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:

Modification Type:MajorLast Reviewed:2/17/2006
Keywords:kbProgramming kbtshoot kberrmsg kbprb KB910436 kbAudDeveloper