AUTHOR: Peter Milchev
DATE POSTED: May 29, 2018
Add headers to requests from ClientDataSource.
This article shows how you can add custom headers to the requests made from the ClientDataSource, for example, Authentication header.
To manipulate the request we should add a handler for the beforeSend event of the underlying Kendo UI DataSource widget's transport properties. In order to do that we need to override the private _mapTransport function of the RadClientDataSource control. Placing the following scripts below the ScriptManager allows you to set a header with key 'customheader' and value 'custom header value'.
var
$ = $ || $telerik.$;
old_mapTransport = Telerik.Web.UI.RadClientDataSource.prototype._mapTransport;
Telerik.Web.UI.RadClientDataSource.prototype._mapTransport =
function
() {
transport = old_mapTransport.call(
this
);
transport.read.beforeSend = beforeSendHandler;
transport.create.beforeSend = beforeSendHandler;
transport.update.beforeSend = beforeSendHandler;
transport.destroy.beforeSend = beforeSendHandler;
return
transport;
}
beforeSendHandler(xhr) {
xhr.setRequestHeader(
'customheader'
,
'custom header value'
Setting the header to the request is not possible when the request data type is JSONP.
Here are some links related to the request headers and JSONP:
Resources Buy Try