I'm using this Ajax code for deleting record. The code works fine in localhost whereas it continuously asks for credentials on hosted server.
and on windows
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();
}
If insert and Updates are working fine on production server then there can't be the issue of Connection string in Web.config.
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. 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With