File upload problem with IIS 6.0

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

Cowboy \(Gregory A. Beamer\) [MVP]

If I remember correctly, ASP.NET does not have write priveleges, by default,
on IIS 6.0. The ASPNET account needs the ability to write to the directory
in question.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
T

Terry Field

The test script below doesn't attempt to write any files to any directory.
This is not a file system permissions issue. That aspect has been
investigated thoroughly.

Cowboy (Gregory A. Beamer) said:
If I remember correctly, ASP.NET does not have write priveleges, by default,
on IIS 6.0. The ASPNET account needs the ability to write to the directory
in question.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top