405 - 'Method Not Allowed' error

Discussion in 'General troubleshooting' started by Brewster, Jun 9, 2009.

  1. I'm new to DiscountASP so I'm hoping this is just a configuration issue but here goes:

    I'm writing an application for use on mobile phones and periodically the application needs to push a small .wav file to the server, placing it in a directory. At the moment whenever I test this I get a 405 error / Method Not Allowed. Essentially IIS-7 is saying the HTTP verb used in the request is invalid which is incorrect. I'm using PUT and PUT is valid. I'm not posting to a page. All I'm looking to do is place the file in the directory.

    Anyhow I can't seem to get past this issue and I need to so I can make progress so any assistance in resolving this will be greatly appreciated.

    Here's the code that pushes the file to the server:

    Code:
     
    private void ButtonSend_Click(object sender, EventArgs e)
    {
    // Set up for sending file to server
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create( --- );
    request.Method = "PUT";
    request.AllowWriteStreamBuffering = true;
    request.ContentType = "audio/wav";
     
     
    // TODO move credential information to config file
    NetworkCredential credentials = new NetworkCredential( ---, ---);
    request.Credentials = credentials;
     
    // initialize byte array for writing WAV file to stream so we can send to server
    int pos = 0;
    byte[] bytes;
    using (BinaryReader reader = new BinaryReader(File.Open(WAVFILE_SAVE_PATH, FileMode.Open)))
    {
    int len = (int)reader.BaseStream.Length;
    bytes = new byte[len];
    while (pos < len)
    {
    bytes[pos] = reader.ReadByte();
    pos++;
    }
    }
    // Set the length of the data we're sending
    request.ContentLength = bytes.Length;
     
    // Try to send the file to the server
    Stream stream = null;
    HttpWebResponse response = null;
    stream = request.GetRequestStream();
    try
    {
    // Push the file to the server
    stream.Write(bytes, 0, bytes.Length);
    stream.Close();
     
    }
    catch (System.Net.WebException webex)
    {
    string tmp = String.Empty;
    if (null != response)
    tmp = "tmpHeader: " + getHeaders(response);
     
    MessageBox.Show(
    "WEB-EXCEPTION: " + webex.Message + " -- " + tmp);
    }
    catch (System.Exception ex)
    {
    MessageBox.Show("EXCEPTION: " + ex.Message + " -- !*! -- " + ex.InnerException);
    }
    finally
    {
    // clean up
    if (null != response)
    {
    response.Close();
    }
    }
     
    // Get the status from the server and show to user
    response = (HttpWebResponse)request.GetResponse();
    MessageBox.Show(
    "StatusDescription: " + ((HttpWebResponse)response).StatusDescription
    );
    }
    
     
  2. Make sure you gave your ASPNet IUSR the appropriate amount of quota to allow files to be uploaded to the server. Go to hosting control panel and click on 'User/Quota Manager' and allocate the appropriate amount of disk space to ASPNet IUSR.

    Second what is the path you are uploading the file to. Make sure it is somewhere inside your root and nowhere else. You only have permission to your root.
     
  3. Raymond;

    Thank you for your reply.

    The path to the directory I'm dropping files in is /messages where '/' is the root directory.

    I've increased the disk quota for the Anonymous ASPuser to 350MB which should be more than sufficient.

    My initial setup I created a user specifically for accessing the messages directory (i.e. my client application) and allocated space to that user and I've also assigned the user to the messages directory. Unfortunately still no luck. I am still receiving the 405 error. Do you have further suggestions?

    Thanks.
     

    Attached Files:

  4. Can you give us the full error message including the stack trace that should come with the error message?
     
  5. Raymond;

    Here's the exception reported:

    Code:
    The remote server returned an error: (405) Method Not Allowed.
    And the stacktrace:


    Code:
    STACK TRACE:
       at System.Net.HttpWebRequest.finishGetResponse()
       at System.Net.HttpWebRequest.GetResponse()
       at SpeakEZ.Client.Client.ButtonSend_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at SpeakEZ.Client.Program.Main()
     

    Attached Files:

  6. Bruce

    Bruce DiscountASP.NET Staff

    are you trying to pull a page from a remote site? you didn't include it in the original code posted.
     
  7. Bruce;

    No, I'm trying to PUT / upload a .wav file in to a directory on the server. No page at all. Just an empty directory to hold the .wav file(s).
     
  8. This is resolved.

    I was trying to essentially FTP a file using the wrong protocol (HttpWebRequest) in the .NET Compact Framework. The .NET Compact Framework doesn't actually support FTP so I had to roll my own.

    Thank you for the suggestions everyone. I do appreciate your attempts to assist.

    Regard,

    B.
     

Share This Page