- Home
- Forum
- JavaScript - EJ 2
- Ej2 FileManager: Throwing error NetworkError: Failed to send on XMLHTTPRequest: Failed to load
Ej2 FileManager: Throwing error NetworkError: Failed to send on XMLHTTPRequest: Failed to load
Hello,
I'm in the process of implementing Ej2 FileManager using physical file approach which I download from: https://github.com/SyncfusionExamples/ej2-aspcore-file-provider/tree/master/wwwroot/Files
The FileManager throwing an error but if I try the API using Swagger everything working fine (returning status 200)
Error:
Success using swagger:
This is my FileManager configuration:
Is there anything I have missed?
Best regards,
Ismail
Greetings from Syncfusion support.
Video demo: https://www.syncfusion.com/downloads/support/directtrac/general/ze/File_Manager_(2)293312250.zip
Service provider: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-aspcore-file-provider-master_(5)-406104639.zip
If your reported problem persists, then please share the following information to validate further.
- If possible, replicate your reported problem in the above provided sample or provide us a simple sample to replicate the issue.
- Elaborate on your issue in detail with video demonstration.
- Are you facing any CORS or other console error while running the File Manager sample? If yes, please share the screenshot of the error.
- Syncfusion package version.
Hello Shalini,
Thank you for your feedback. I have found the problem that causing this, that is because FileManager POST did not send CSRF token. For your information, all off my API should comply with the CSRF for security reason. For now, I have disabled CSRF at API consumed by FileManager AjaxSettings by adding: [IgnoreAntiForgeryToken] to the API controller:
For complete solution, I should be able sent the CSRF token. Could you please share a way to intercept the POST from FileManager so I can add CSRF token to the "headers"? I have try that through "beforeSend" event, but still no luck. Could you please share information of how to update the "headers" before it POST ed?
Thank you
Best regards,
Ismail
Thanks for the update.
|
var fileObject = new ej.filemanager.FileManager({
ajaxSettings: {
. . .
}, beforeSend: function(args) {
args.ajaxSettings.beforeSend = function(args) {
args.httpRequest.setRequestHeader('Authorization', 'CSRF-Token'); //you can pass the CSRF token here
};
}
}); |
You can access the passed token value in the FileOperations method of server as demonstrated in the below code snippet,
|
public object FileOperations([FromBody] FileManagerDirectoryContent args)
{
var val = HttpContext.Request.Headers["Authorization"];
if (args.Action == "delete" || args.Action == "rename")
{
}
} |
Please find the below sample for your reference
https://ej2.syncfusion.com/javascript/documentation/api/file-manager/beforeSendEventArgs/#ajaxsettings
Please get back to us if you need further assistance.
Regards,
Shalini M.
Hi Shalini,
Thank you for your help. The answer you provide enable me to send custom header before send the ajax.
Best regards,
Ismail
- 5 Replies
- 3 Participants
- Marked answer
-
IH ISMAIL HAMZAH
- Aug 30, 2021 06:06 PM UTC
- Sep 13, 2021 05:17 AM UTC