Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net Ajax Delete Record not working on Production Server

I'm using this Ajax code for deleting record. The code works fine in localhost whereas it continuously asks for credentials on hosted server.

enter image description here

and on windows

enter image description here

With all of the participants'suggestions, I mostly suspect now on two things.

1) The web hosting is a cheap shot and isn't updating for the Application rights despite several efforts (Needs to contact server level support)

2) Probably the message box is requiring some token for authentication like this

$(document).ready(function () {
   $('.js-delete').on('click', function () {
        var button = $(this);
        var buttonId = button.attr("data-id");
        //var container = $(this).parent().siblings('#tablex').find('#hiddenTable').clone();

        var box = bootbox.dialog({
        show: false,
        message: "Are you sure you want to delete the Record?",
        title: "Delete Record?",

    buttons: {

        cancel: {
            label: "Cancel",
            className: "btn-default"
        },
      ok: {
        label: "Delete",
        className: "confirm btn btn-danger",
        callback: function (result) {
            if (result) {
                $.ajax({
                    url: "/api/datax/delete/" + button.attr("data-id"),
                    method: "Delete",
                    success: function () {
                        button.parents("tr").remove();
                    }
                });
            }
            console.log('Button Pressed.');
        }
      }
     }
    });
   });
});

And in my Controller, I'm handling this delete call like this.

 [Route("api/datax/delete/{id}")]
    public void Delete(int id)
    {
        var dataInDb = _context.Datax.SingleOrDefault(c => c.Id == id);

        if (dataInDb == null)
        {
            throw new HttpResponseException(HttpStatusCode.NotFound);
        }

        _context.Datax.Remove(dataInDb);
        _context.SaveChanges();

    }
like image 620
Naveed Abbas Avatar asked Nov 21 '17 10:11

Naveed Abbas


2 Answers

If insert and Updates are working fine on production server then there can't be the issue of Connection string in Web.config.

  • Try manually deleting records from DB logging as user whose credentials you are using in Web.Config while working with production server, and check weather it is allowing or not. If it don't allow then you need to give the rights of deleting along with read/write in SQL server.
like image 125
Divya Avatar answered Nov 15 '22 00:11

Divya


1) Please check if the HTTP-Delete-Method is allowed on the Webserver

2) Does the domain-part of the frontend differ from the webservice? If it does, check your browser console output for errors regarding CORS, which means that the browser thinks you are doing some cross-site scripting

3) In Internet Explorer we had a problem with Kerboros-Authentication. The browser did not hand the authentication tokens around. Not sure if that screenshot is IE, but if it is, check if switching the following settings change the behaviour:

Extras => Internet options => Advanced => Security : "Activate integrated windows authentication" and "enable advanced protection mode" (or something sounding similar, i´ve translated the names from german)

like image 1
Brandtware Avatar answered Nov 15 '22 00:11

Brandtware