Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Ajax post results in bad request error #6247


User avatar
0
entripy created

I am working on ASP.NET Zero which is built on ASP.NET Core. I was getting a bad request error when I used KendoUI Upload control on one of my pages. After lot of research and investigation, I realized the HTTP POST Ajax request is failing with 400 bad request error. My code samples below have some commented line for other scenarios I test. None of the existing posts in stack over flow solved my issue. I Below is my ajax call:

$.ajax({ url: "/test/TestCall", type: 'Post', /* data: JSON.stringify({ "Param1": "test" }), dataType:"json", processData: false, */// tell jQuery not to process the data contentType: "application/json", // tell jQuery not to set contentType success: function (result) { var res = result; }, error: function (jqXHR) { var z = 3; }, complete: function (jqXHR, status) { var x = 10; } }); My Controller code is: I also tried without extending from MyTestProjectControllerBase and just using the Controller base class. It did not work.

public class TestController : MyTestProjectControllerBase { public IActionResult Index() { return View(); }

[HttpPost] public ActionResult TestCall() { //return Content("Name is:" ); return new ContentResult() { Content = "test" }; } } What am I missing? I tried using postman and I see this additional information 'Request cannot be fulfilled due to bad syntax'

could not figure it out after spending good 8 hours on this issue. Not sure if the issue is with Asp.net core or asp.net zero. Any pointers would be greatly appreciated.


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    check the XSRF CSRF Protection document: https://aspnetboilerplate.com/Pages/Documents/XSRF-CSRF-Protection#asp-net-core