I am building a new ASP.NET 5 website with MVC/Web Api, and hosting this on an Azure Website. I currently am running with beta 8.
My problems came when I built a controller with a POST method. Whenever I would deploy to my Azure Website calling the POST always results in a 502 Bad Gateway Error. "The CGI Application encountered an error and the server terminated the process". This same method works locally.
After a troubleshooting the issues I traced the problem down to a piece of Middleware I wrote that essentially sends a 302 Redirect whenever the request comes in on HTTP. The 302 sends the requests to the same host/path/query only on HTTPS.
When I remove this middleware the POST Works. Obviously this is causing the issue, but I have 2 questions.
My Middleware code:
if(!context.Request.IsHttps){
var withHttps = "https://" + context.Request.Host + context.Request.Path;
if(context.Request.QueryString.HasValue){
withHttps += context.Request.QueryString.Value;
}
context.Response.Redirect(withHttps);
}
else{
if(m_Next != null)
await m_Next(context);
}
The problem is redirecting changes your POST HTTP command to GET command.
You have two choices:
Just found this on SO, it has information that might help you:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With