I have at backend the [ValidateAntiForgeryToken]
decorator, but I'm currently unable to make Ajax
requests for SyncFusion FileManager. It basically starts with a simple code like this:
let fileManager = new ej.filemanager.FileManager({
ajaxSettings: {
url: '/FileManager/List',
},
toolbarSettings: {
items: ['NewFolder', 'Upload', 'Download', 'Delete', 'Rename', 'SortBy', 'Refresh']
},
view: 'Details',
enableNavigation: true
});
fileManager.appendTo('#fileManager');
Then it displays an error: NetworkError: Failed to send on XMLHTTPRequest: Failed to load /FileManager/List
and I'm getting error 400.
When I inspect backend I see that it doesn't enters at controller action. But if I remove the decorator then it works as expected. Seems to me that the issue lies on the AntiForgeryToken
validation. The token
is correctly set at View and JS.
How can I adapt current fileManager
and make this work?
Other places I succesfully make requests like this:
$.ajax({
url: '/Other/Action',
type: 'POST',
async: true,
data: {
__RequestVerificationToken: token,
jsonData: jsonData,
},
success: function () {
//code here
},
error: function () {
//code here
}
});
I've tried:
- Changing from
application/json
toapplication/x-www-form-urlencoded; charset=UTF-8
- Adding
RequestVerificationToken
at header - Adding
data: JSON.stringify({ __RequestVerificationToken: token, })
toajaxSettings
- Some other alternative with
beforeSend: function (args)
as suggested by LLM