T
Terry Field
We've recently moved an application from a W2K server to a Windows 2003
server with IIS 6.0 and in the process managed to lose the ability to handle
file uploads. I've managed to identify that this is not specific to IIS 6.0
since we have another server that doesn't give me any problems in this
respect.
The test program below illustrates the problem. The Page_Load method never
resolves the IsPostBack property to true and the btnUpload_ServerClick event
never fires. When I change the web.config to enable trace in pageOutput
mode, it shows that a POST is in fact received. This test file runs fine
under any other server that I have tried it on (IIS5.0 IIS5.1 IIS6.0).
The server giving me trouble is a production server and has security policy
fairly well locked down. I couldn't identify anything in the policy that may
be causing this however.
Anyone got any clues?
Terry Field.
------- Test file starts here ----------------------------
<%@ Page language="c#" runat="server" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>FileUpload</title>
</head>
<body>
<script language="C#" runat="server">
void btnUpload_ServerClick(object sender, System.EventArgs e) {
if (fileUpload.PostedFile == null) {
Response.Write("No file specified");
return;
}
int len = (int) fileUpload.PostedFile.InputStream.Length;
if (len == 0) {
Response.Write("File is empty or failed to upload");
return;
}
byte[] data = new byte[len];
try {
fileUpload.PostedFile.InputStream.Read(data, 0, len);
}
catch {
Response.Write("Failed to read upload");
return;
}
if (data.Length == len) {
Response.Write("Load Succeeded(" + len.ToString() + " bytes)");
}
else {
Response.Write("Unknown error");
}
}
void Page_Load() {
if (IsPostBack)
Response.Write("<p>Current request is POST</p>");
else
Response.Write("<p>Current request is GET</p>");
}
</script>
<form id="fileUpLoadForm" method="post" enctype="multipart/form-data"
runat="server">
<input type="file" id="fileUpload" name="fileUpload" runat="server">
<br>
<input id="btnUpload" type="submit" value="Upload" runat="server"
name="btnUpload" onserverclick="btnUpload_ServerClick">
<br>
<span id="spanError" runat="server"></span>
</form>
</body>
</html>
server with IIS 6.0 and in the process managed to lose the ability to handle
file uploads. I've managed to identify that this is not specific to IIS 6.0
since we have another server that doesn't give me any problems in this
respect.
The test program below illustrates the problem. The Page_Load method never
resolves the IsPostBack property to true and the btnUpload_ServerClick event
never fires. When I change the web.config to enable trace in pageOutput
mode, it shows that a POST is in fact received. This test file runs fine
under any other server that I have tried it on (IIS5.0 IIS5.1 IIS6.0).
The server giving me trouble is a production server and has security policy
fairly well locked down. I couldn't identify anything in the policy that may
be causing this however.
Anyone got any clues?
Terry Field.
------- Test file starts here ----------------------------
<%@ Page language="c#" runat="server" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>FileUpload</title>
</head>
<body>
<script language="C#" runat="server">
void btnUpload_ServerClick(object sender, System.EventArgs e) {
if (fileUpload.PostedFile == null) {
Response.Write("No file specified");
return;
}
int len = (int) fileUpload.PostedFile.InputStream.Length;
if (len == 0) {
Response.Write("File is empty or failed to upload");
return;
}
byte[] data = new byte[len];
try {
fileUpload.PostedFile.InputStream.Read(data, 0, len);
}
catch {
Response.Write("Failed to read upload");
return;
}
if (data.Length == len) {
Response.Write("Load Succeeded(" + len.ToString() + " bytes)");
}
else {
Response.Write("Unknown error");
}
}
void Page_Load() {
if (IsPostBack)
Response.Write("<p>Current request is POST</p>");
else
Response.Write("<p>Current request is GET</p>");
}
</script>
<form id="fileUpLoadForm" method="post" enctype="multipart/form-data"
runat="server">
<input type="file" id="fileUpload" name="fileUpload" runat="server">
<br>
<input id="btnUpload" type="submit" value="Upload" runat="server"
name="btnUpload" onserverclick="btnUpload_ServerClick">
<br>
<span id="spanError" runat="server"></span>
</form>
</body>
</html>