IIS 7.5 - Windows Server 2008 - Error loading file 405. Code works on Windows 2003 server

I got a problem where the following code works on a Windows 2003 machine and now we upgrade to 2008 and it doesn't work anymore. When the code gets into getResponse () it gives me a 405 error.

I am writing to a virtual directory via IIS.
I also tried to make this app and it doesn't matter. We don't have webdav installed / enabled.

I have searched everywhere and cannot find the right solution to allow me to write the file.

I have included the basic code that is used to upload files ...

saveLocation.Length = 0;
saveLocation.Append(Path.GetFileName(files[0]));

   inStream = File.Open(files[0], FileMode.Open);
    HttpWebRequest myWebRequest =    (HttpWebRequest)WebRequest.Create("http://localhost/kw/archive/testFile.pdf");

      myWebRequest.ContentType = contentType;
      myWebRequest.Method = "put";
      //myWebRequest.Headers.Add("action", "put");
      myWebRequest.Headers.Add("filename", saveLocation.ToString());
      myWebRequest.ContentLength = inStream.Length;

      dataToRead = (int)inStream.Length;
      outStream = myWebRequest.GetRequestStream();

      while (dataToRead > 0) {
        if (Response.IsClientConnected) {
          length = inStream.Read(buffer, 0, 10000);
          outStream.Write(buffer, 0, length);
          buffer = new Byte[10000];
          dataToRead = dataToRead - length;
        }
        else {
          dataToRead = -1;
        }
      }

      HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();

      myWebResponse.Close();
      inStream.Close();
      outStream.Close();

      

update: I am currently getting 405 error.

+3


source to share


3 answers


405 error means that the method is not allowed. The above code uses the "PUT" method. I believe this method is not allowed in IIS. Try enabling this and then check it out. If you have an idea how to enable this than try it, and if not, check this link . Hope this solves your problem.



0


source


405 Means Method Not Allowed - The most likely reason for this is that the PUT verb was not allowed through the IIS settings. I believe this is a security setting that lingered between IIS6 and IIS7 in that PUT and DELETE requests are now blocked by default.

To enable PUT requests in IIS Manager in Site Settings, there is an icon that says "Request Filtering". If you open this, you will see several tabs, one of which is called HTTP VERBS, switch to that. Select "Allow Verb" in the Actions panel on the right and enter PUT in the dialog that appears and select "OK."

Alternatively, you can add the following to your web.config file:



<security>
    <requestFiltering>
        <verbs allowUnlisted="false">
            <add verb="PUT" allowed="true" />
        </verbs>
    </requestFiltering>
</security>

      

If that doesn't work, we'll need to think more about what's on the receiving end of this call. What is the code that receives the request?

0


source


IIS 6 uses the Network Service account for this worker process, IIS 7 uses the DefaultAppPool ID.

Make sure the physical folder has write access to identify the DefaultAppPool.

See this article on how to add the DeaultAppPool ID to a folder.

http://www.iis.net/learn/manage/configuring-security/application-pool-identities

0


source







All Articles