Http error 405, Method not allowed (How to allow POST in ASP.NET?)
<p>I am catching 405 error when I am trying to POST with HttpWebRequest/HttpWebResponse from a console application to an aspx. My asp.net page has no web controls or UI. Only action performed by the aspx is forwarding posted data to another location.
Console application looks like this:</p>

<pre><code>public static void Main(string[] args)
{
  try
  {
   string postData = string.Concat("requestXML=","Test data to send");
   byte[] dataToSend = Encoding.Default.GetBytes(HttpUtility.UrlEncode(postData));

   HttpWebRequest httpRequest = WebRequest.Create(_host) as HttpWebRequest;
   httpRequest.Method = WebRequestMethods.Http.Post;
   httpRequest.ContentType = @"application/x-www-form-urlencoded; charset=UTF-8";
   httpRequest.CookieContainer = new CookieContainer();
   httpRequest.ContentLength = dataToSend.Length;

   using (Stream postDataStream = httpRequest.GetRequestStream())
   {
    postDataStream.Write(dataToSend, 0, dataToSend.Length);
   }

   HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse;
   string response;
   using (StreamReader reader = new StreamReader(httpResponse.GetResponseStream()))
   {
    response = reader.ReadToEnd();
   }

   Console.WriteLine("Response: {0}",response);
   Console.ReadLine();
 }
 catch (Exception ex)
 {
   Console.WriteLine("Error: {0}",ex.Message);
   Console.ReadLine();
 }
}
</code></pre>

<p>Tha aspx contains the following code:</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        string postData;
        using (StreamReader reader = new StreamReader(Request.InputStream))
        {
            postData = reader.ReadToEnd();
        }
        byte[] dataToSend = Encoding.Default.GetBytes(postData);

        HttpWebRequest httpRequest = WebRequest.Create(_host) as HttpWebRequest;
        httpRequest.Method = WebRequestMethods.Http.Post;// Request.HttpMethod;
        httpRequest.ContentType = @"application/x-www-form-urlencoded; charset=UTF-8"; //Request.ContentType;
        httpRequest.ContentLength = dataToSend.Length;

        using (Stream postDataStream = httpRequest.GetRequestStream())
        {
            postDataStream.Write(dataToSend, 0, dataToSend.Length);
        }

        HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse;
        string response;
        using (StreamReader reader = new StreamReader(httpResponse.GetResponseStream()))
        {
            response = reader.ReadToEnd();
        }
        Response.Write(response);
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
}
</code></pre>

<p>Is anybody know how to enable the POST method in aspx page?</p>

<p>Thanks to all!</p>

<p>PS. the following settings in web.config has no effect in my scenario:</p>

<pre><code>&lt;authorization&gt; &lt;allow verbs="POST" users="*"/&gt; &lt;/authorization&gt;
</code></pre>
