Datatables Working on Local Host but when published to Web app get error 404

Datatables Working on Local Host but when published to Web app get error 404

davey.cawooddavey.cawood Posts: 11Questions: 2Answers: 0

Hi,
I have an issue when using aspnet.core 2.1, I have datatables controller for my database which connects to the azure hosted sql server database.
This works fine when using IIS Express Localhost however when I publish the project to a web application I get an the following error,
DataTables warning: table id=example - Ajax error. For more information about this error, please see http://datatables.net/tn/7.
The connection string I am trying to use has windows login and I believe this error may be due to the api request (http post and get) as it says the api url cannot be found error 404 or possibly due to the antiforgery token in the ajax request?

Answers

  • kthorngrenkthorngren Posts: 9,769Questions: 25Answers: 2,255

    url cannot be found error 404 or possibly due to the antiforgery token in the ajax request?

    You will need to look at your server logs and configuration to determine the exact cause of the 404. The Cross-Site Request Forgery docs may be helpful.

    Kevin

  • davey.cawooddavey.cawood Posts: 11Questions: 2Answers: 0

    It is still not finding the api Url from the controller?

  • kthorngrenkthorngren Posts: 9,769Questions: 25Answers: 2,255

    The 404 error is returned from your server. That is the place to look to find out why the server is responding with the 404. The server logs should provide details of why the error is occurring.

    Kevin

  • davey.cawooddavey.cawood Posts: 11Questions: 2Answers: 0

    Yes the server logs show the error is in the ajax request and is now giving a status code 400 Bad Request

  • kthorngrenkthorngren Posts: 9,769Questions: 25Answers: 2,255

    Do the server logs indicate why its a bad request?

    Maybe this troubleshooting link will help:
    https://airbrake.io/blog/http-errors/400-bad-request

    Kevin

  • davey.cawooddavey.cawood Posts: 11Questions: 2Answers: 0

    No it does not appear to indicate why

  • allanallan Posts: 52,268Questions: 1Answers: 7,958 Site admin

    Could you show me your controller code please? Most likely its something to do with the routing, but I'm not sure what. The controller will be where we can start though.

    Allan

  • davey.cawooddavey.cawood Posts: 11Questions: 2Answers: 0
    edited January 22

    [Route("/Issues/Data")]
    [HttpGet]
    [HttpPost]

        public ActionResult Issues()
        {
            var dbConnection = Environment.GetEnvironmentVariable("DbConnection");
    
            using (var db = new Database("sqlserver", "dbConnection"))
            {
                var response = new Editor(db, "Issues")
    
                     .Model<IssuesTestModel>()
    
    
                          .Pkey("Issues.Id_Issues")
                     .Field(new Field("Issues.Number").SetFormatter(Format.IfEmpty(null)))
                     .Field(new Field("Issues.Title").SetFormatter(Format.IfEmpty(null)))
                     .Field(new Field("Issues.Description").SetFormatter(Format.IfEmpty(null)))
    
                     .TryCatch(false)
                        .Process(Request)
                        .Data();
                return Json(response);
    
    
    
    
            }
    
        }
    
  • allanallan Posts: 52,268Questions: 1Answers: 7,958 Site admin

    Thank - so if you load:

    {{domain/ip:port}}/Issues/Data

    in your browser, what do you get? Is it still a 404 or 400 error?

    Allan

  • davey.cawooddavey.cawood Posts: 11Questions: 2Answers: 0

    404 error still

  • allanallan Posts: 52,268Questions: 1Answers: 7,958 Site admin

    Okay good - so its a routing issue.

    I guess the key question now is what is the difference between your local ISS Express server and the remote server? What versions of ISS are they running? What versions of .NET Framework, etc?

    Allan

  • paulwingspaulwings Posts: 1Questions: 0Answers: 0

    The 400 Bad Request error is an HTTP status code indicates that the request you sent to the webserver was malformed , in other words, the data stream sent by the client to the server didn't follow the rules. It means that the request itself has somehow incorrect or corrupted and the server couldn't understand it. There are a number of different causes for a 400 Bad Request Error . It might be a malformed request syntax, invalid request message framing, or deceptive request routing . In most cases, the problem is on the website itself, and there's not much you can do about that.

Sign In or Register to comment.