I have the following action code to accept a service request:
namespace MyStuff.api
{
[RoutePrefix("api/Dy")]
[EnableCors(origins: "*", headers: "*", methods: "*")]
[Authorize]
public class DyController : ApiController
{
//...
[Route("{pit}/{name}")]
public void Post(string pit, string name, [FromBody]JObject obj)
{
//...
#region do something
// work with name here
#endregion
}
//...
}
}
Test Scenario
I'm in the debugger and a breakpoint is set somewhere inside the Post method. In the data set I found a brand name "3.1 Phillip Lim". I try to figure out how I can manipulate this name (and other similarly creative names) so that the Post method gets hit.
Breakpoint not hit - request does not arrive in thePost
method
- $.post("http://undisclosed.server.net/api/Dy/Brands/3.1%20Phillip%20Lim", MyStuff.Brands[30], function (result) { MyStuff.BrandsResult = result; })
- $.post("http://undisclosed.server.net/api/Dy/Brands/-3.1%20Phillip%20Lim", MyStuff.Brands[30], function (result) { MyStuff.BrandsResult = result; })
- $.post("http://undisclosed.server.net/api/Dy/Brands/id-3.1%20Phillip%20Lim", MyStuff.Brands[30], function (result) { MyStuff.BrandsResult = result; })
- $.post("http://undisclosed.server.net/api/Dy/Brands/body.Name", MyStuff.Brands[30], function (result) { MyStuff.BrandsResult = result; })
- $.post("http://undisclosed.server.net/api/Dy/Brands/{body.Name}", MyStuff.Brands[30], function (result) { MyStuff.BrandsResult = result; })
Breakpoint hit - request arrives as expected
$.post("http://undisclosed.server.net/api/Dy/Brands/body-Name", MyStuff.Brands[30], function (result) { MyStuff.BrandsResult = result; })
$.post("http://undisclosed.server.net/api/Dy/Brands/{null}", MyStuff.Brands[30], function (result) { MyStuff.BrandsResult = result; })
WebApi 2 obviously does something behind the scenes - might be some kind of type recognition for the segments in the URL...
Please explain what is going on ... or how you worked around this. Thanks.