请按照此 Microsoft 文章中的说明进行操作:
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/register-sharepoint-add-ins
注册外接程序后,在创建 SharePoint 上下文时执行此操作(使用 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 应该类似于:
NONISV|{您的公司名称}|{您的加载项名称}/1.0
如此处所述。祝你好运!