更新时间:2022-06-07 23:31:02
按照这篇 Microsoft 文章中的说明进行操作:
Follow the instructions in this Microsoft article:
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/register-sharepoint-add-ins
注册加载项后,在创建 SharePoint 上下文(使用 CSOM)时执行此操作:
When you have your Add-In registered, do this when you are creating SharePoint Context (using CSOM):
private void Initialize()
{
this.SPCurrentContext = new ClientContext(this.Url);
if (string.IsNullOrWhiteSpace(this.Domain))
{
this.SPCurrentContext.Credentials = new SharePointOnlineCredentials(this.User, ParseToSecureString(this.Password));
}
else
{
this.SPCurrentContext.Credentials = new NetworkCredential(this.User, ParseToSecureString(this.Password), this.Domain);
}
this.RetryCount = Properties.Settings.Default.DefaultRetryCount;
this.RetryDelay = Properties.Settings.Default.DefaultRetryDelay;
this.NONISV = Properties.Settings.Default.ClientAppNONISV;
this.SPCurrentContext.ExecutingWebRequest += delegate (object sender, WebRequestEventArgs e)
{
e.WebRequestExecutor.WebRequest.UserAgent = this.NONISV; // This is the TRICK!!!
};
}
用作用户代理 HTTP 标头的 NONISV 应该类似于:
The NONISV used as User-Agent HTTP Header should be something like:
NONISV|{您的公司名称}|{您的加载项名称}/1.0
NONISV|{Your Company Name}|{Your Add-In Name}/1.0
如此处.祝你好运!