背景:将js脚本挂载在Sharepoint(以下简称sp)站点上从而构建可与sharepoint交互的web 应用。
问题:一旦页面长期没有和sharepoint进行交互(调用sp List API,文档库api等),当前页面维持的验证将会在默认时间之后过期,一般是30 minutes。这个时候再去向sharepoint上传文件时,会出现:The security validation for this page is invalid and might be corrupted. Please use your web browser’s Back button to try your operation again.
解决方法:
function listenSPPageDigest() {
var updateSPDigest = function () {
var pagaContextInfo = window._spPageContextInfo,
spDigestRefreshInterval = window._spFormDigestRefreshInterval,
siteRelativeUrl;
if (pagaContextInfo !== undefined && typeof pagaContextInfo.webServerRelativeUrl === ‘string’ && typeof spDigestRefreshInterval === ‘number’) {
siteRelativeUrl = pagaContextInfo.webServerRelativeUrl;
window.UpdateFormDigest(siteRelativeUrl, spDigestRefreshInterval);
}
};
window.setInterval(updateSPDigest, 1750000);
}
在一个只加载一次的js程序里调用以下方法,在单页面应用中,在容器js执行中调用就ok。
listenSPPageDigest();
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/15359.html