Add AntiForgeryToken to all operations

Add AntiForgeryToken to all operations

shuminliushuminliu Posts: 14Questions: 6Answers: 0
edited November 2020 in Free community support

I'd like to add AntiForgeryToken to all the CRUD calls to the server to prevent CSRF. I'm wondering if it's possible to inject a token to the POST, either in the ajax config, or in the DataTable config.

Thanks!

 $('#my-data-table').DataTable({
            dom: "Blfrtip",
            responsive: true,
            ajax: {
                url: "/api/ProcessData",
                type: "POST"
            },

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    Use ajax.data.

    Kevin

  • shuminliushuminliu Posts: 14Questions: 6Answers: 0

    Got it. Thanks!

    $('#my-data-table').DataTable({
    dom: "Blfrtip",
    responsive: true,
    ajax: {
    url: "/api/ProcessData",
    type: "POST",
    data: {"__RequestVerificationToken": the_token}
    },

This discussion has been closed.