I have a problem to upload file to the server form win form. I am using VS2005, the server is Windows 2003. In IIS I have assign everyone full permition to that virtual directoty and also anonymous access is enabled. But I still get error as "The remote server returned an error: (403) Forbidden". However, I can download file from that directoy and I can access http://server1/webservice1/upload by IE My code is as following: Please help.
HttpWebRequest req = (HttpWebRequest)WebRequest.Create "http://server1/webservice1/Service.asmx/upload");
req.Method = "PUT";
req.AllowWriteStreamBuffering = true;
req.Credentials = CredentialCache.DefaultCredentials;
//// Retrieve request stream
Stream reqStream = req.GetRequestStream();
// Open the local file
FileStream rdr = new FileStream(DBConnection.DataSourceDirectoy, FileMode.Open);
// Allocate byte buffer to hold file contents
byte inData = new byte;
// loop through the local file reading each data block
// and writing to the request stream buffer
int bytesRead = rdr.Read(inData, 0, inData.Length);
while (bytesRead > 0)
reqStream.Write(inData, 0, bytesRead);
bytesRead = rdr.Read(inData, 0, inData.Length);
catch (Exception x)
ThanksFriday, September 08, 2006 7:11 AM
You have to grant both of these:
Friday, September 08, 2006 1:46 PM
- write permission to the virtual directory in IIS (i.e. the permission for HTTP PUT). Without, you'll get a HTTP 403 error.
- write permission for the IIS process identity (e.g. IUSR_<MACHINENAME>) on the actual directory on the file system. Without, you'll get a HTTP 401 error.
Thanks for reply:
I have done what you asked above, I assigned the full permissions to the virtual directory in IIS include “scrit source access, read, write, directory browing, log visits, index this resource” plus execute permissions with “Scripts and executables”. I also tried to use both IUSR_<MACHINENAME> and Administrator account under Directory security in IIS. However I still get the same 403 error.
Another thing I feel strange, I can access this file upload directory in IE with http://server1/webservices1/upload , but in the WebRequest I need to use directory as http://server1/webservice1/Service.asmx/upload , which is not accessible in IE. I am not sure if it has something to do with 403 error.
ThankMonday, September 11, 2006 4:23 AM