POSTing data to WebApi after update to 5.1.0 fails
I found the problem.
My post code uses $.ajax(...), as shown in initial message.
But jquery's .ajax post data as application/x-www-form-urlencoded.This worked in previous versions of WebAPI, but in latest update it seems it doesn't accept application/x-www-form-urlencoded by default.
I changed content type to application/json, and I had to convert data to json, and this solved the problem.
So, instead of
j$.ajax({ type: "POST", url: uri, data: dataObj, success: function(...)
I had to change to
j$.ajax({ type: "POST", url: uri, data: JSON.stringify(dataObj), contentType: "application/json; charset=utf-8", success: function(...)
First clue:
Removing enableCrossAppRedirects="true" from Authentication settings of web.config resolved the issue in my case. Thanks to @kiran-challa
Ok, I found the fix for this without a work around.
Refer to this thread:h t t p : / / a s p n e t w e b s t a c k . c o d e p l e x . c o m/discussions/524616
This is a bug in 5.1 - it is resolved in a nightly buildSee: https://aspnetwebstack.codeplex.com/and specifically Signed nightly builds:
"Nightly builds can be used with Visual Studio 2010 SP1 or Visual Studio 2012. To use the nightly build:1.In your Package Manager settings add the following package source: ....
2.Add or update to the latest build of ASP.NET. The nightly build is labeled (nightly YYYY MMM DD). "
this fixed the post issues for me (no need to use JSON.stringify anymore) and also fixed multi-part posting for a module that was uploading a file.
Hope this helps someone else!And hopefully there will be a proper patch for this soon.