locked
The remote server returned an error: (403) Forbidden with HttpWebRequest put method

    Question

  • Hi all:

         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[4096];

                // 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);
                }

                rdr.Close();
                reqStream.Close();

                try
                {
                    req.GetResponse();
                }
                catch (Exception x)
                {
                    MessageBox.Show(x.Message);
                }

       Thanks

    Friday, September 08, 2006 7:11 AM

Answers

  • Sorry, I had missed the fact that you're trying to PUT to the path info of a Web Service endpoint. Which begs the question "why"? There's no defined binding for SOAP 1.x and HTTP PUT. You should POST instead.
    Wednesday, September 13, 2006 8:28 AM

All replies

  • You have to grant both of these:

    • 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. 
    Friday, September 08, 2006 1:46 PM
  • 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.

     

    Thank

    Monday, September 11, 2006 4:23 AM
  • Sorry, I had missed the fact that you're trying to PUT to the path info of a Web Service endpoint. Which begs the question "why"? There's no defined binding for SOAP 1.x and HTTP PUT. You should POST instead.
    Wednesday, September 13, 2006 8:28 AM