使用 Kendo UI 数据源的 Authorization 标头拦截器 [英] Interceptor for Authorization headers using Kendo UI datasource

查看:10
本文介绍了使用 Kendo UI 数据源的 Authorization 标头拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 webapi 并限制 web api 通过令牌进行身份验证,因此为了填充数据源,我在数据源中使用请求标头.

I am using webapi and restrict web api's to authenticate by token, so to populate datasource I use request headers in DataSource.

var abcDatasource = new kendo.data.DataSource({
    transport: {
        read: {
            url: '/api/exampledata',
            dataType: 'json',
            headers: { 'Authorization': 'Bearer ' + accesstoken }
        },
    },
    pageSize: 5, 

});

以下代码行需要在所有数据源重复

the below line of code need to repeat at all datasource

headers: { 'Authorization': 'Bearer ' + accesstoken }

是否可以制作中心函数来覆盖向请求标头提供令牌的剑道数据源标头?因为我有 600 多个数据源,所以我只想在一个地方设置令牌.

Is it possible to make central function which overwrite the kendo datasoruce headers that provides the token to the request headers? because i have more than 600 datasources, I just want to have token setup in one place.

推荐答案

是的,您可以在每次发送请求时全局设置特定的标头.试试这个,

Yes, you can globally set a specific header every time you send a request. Try this one,

$(document).ajaxSend(function (event, jqXHR, options) {
    jqXHR.setRequestHeader('Authorization', 'Bearer ' + accesstoken);
});

这篇关于使用 Kendo UI 数据源的 Authorization 标头拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆