Articles in this section
Category / Section

How to add custom header in ASP.NET MVC FileExplorer Ajax request?

1 min read

Adding custom headers in Ajax request of FileExplorer

You can add custom header in Ajax Request of ASP.NET MVC FileExplorer. Whenever an Ajax request is about to be sent, our FileExplorer triggers the beforeAjaxRequest event. Using this event, you can add the custom header in Ajax Request of FileExplorer.

 

[Javascript]

 

$("#fileExplorer").ejFileExplorer({
            isResponsive: true,
            width: "100%",
            path: "https://js.syncfusion.com/demos/ejServices/Content/FileBrowser/",
            ajaxAction: ajaxActionHandler,
            ajaxSettings: {
                // Using “beforeSend” event, you can specify your custom method.
                read: { beforeSend: beforeAjaxRequest },
                createFolder: { beforeSend: beforeAjaxRequest },
                remove: { beforeSend: beforeAjaxRequest },
                rename: { beforeSend: beforeAjaxRequest },
                paste: { beforeSend: beforeAjaxRequest },
                getDetails: { beforeSend: beforeAjaxRequest },
                search: { beforeSend: beforeAjaxRequest }
            },
           //Using “beforeAjaxRequest” event, you can specify your custom header 
            beforeAjaxRequest: "beforeAjaxRequestSent"
});
 
function beforeAjaxRequestSent(args) {
   args.ajaxSettings.beforeSend = function (xhr) {
        xhr.setRequestHeader('x-requested-with', 'some value');
   }
}

 

If you want to add custom header for specific FileExplorer operation Ajax Request, use the ajaxSettings property of FileExplorer. The following code sample demonstrates this behavior. 

 

[Javascript]

 

function beforeAjaxRequest(xhr) {
          xhr.setRequestHeader('x-requested-with', 'some value');
}

 

The above two ways have been showcased in the following playground sample: https://jsplayground.syncfusion.com/cfa1jo33

 

Conclusion

I hope you enjoyed learning about how to add custom header in ASP.NET MVC FileExplorer Ajax Requests.

You can refer to our ASP.NET MVC File Explorer feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET MVC File Explorer example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied