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
SYMPTOMSConsider 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 CAUSEThis 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.RESOLUTIONThis problem is fixed in IIS 6.0. IIS 6.0 is included with Microsoft Windows Server 2003.WORKAROUNDTo 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 exampleprotected 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 exampleSub 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 STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
Modification Type: | Major | Last Reviewed: | 2/17/2006 |
---|
Keywords: | kbProgramming kbtshoot kberrmsg kbprb KB910436 kbAudDeveloper |
---|
|