Microsoft KB Archive/910436

= 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 =

Article ID: 910436

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft Internet Information Services 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(&quot;FileUpload.aspx &quot;)) {       // 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(&quot;ErrorPage.aspx&quot;); }   } }

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(&quot;FileUpload.aspx&quot;)) 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(&quot;ErrorPage.aspx&quot;) End If       End If End Sub



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; 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.  Note The size for the maxRequestLength attribute is in KB.

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

FileUpload class

http://msdn2.microsoft.com/en-us/library/ysf0192b(en-US,VS.80).aspx

 element

http://msdn2.microsoft.com/en-us/library/e1f13641(vs.71).aspx

Machine configuration files

http://msdn2.microsoft.com/en-us/library/ms229697(vs.71).aspx

Keywords: kberrmsg kbtshoot kbprogramming kbprb KB910436

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.