最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

SyncFusion JavaScript and RequestVerificationToken - Stack Overflow

programmeradmin1浏览0评论

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 to application/x-www-form-urlencoded; charset=UTF-8
  • Adding RequestVerificationToken at header
  • Adding data: JSON.stringify({ __RequestVerificationToken: token, }) to ajaxSettings
  • Some other alternative with beforeSend: function (args) as suggested by LLM
发布评论

评论列表(0)

  1. 暂无评论