How to solve Sharepoint CSOM HTTP Request Error 429?

久未见 提交于 2019-12-01 14:27:49

Follow the instructions in this Microsoft article:

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/register-sharepoint-add-ins

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!!!
        };
    }

The NONISV used as User-Agent HTTP Header should be something like:

NONISV|{Your Company Name}|{Your Add-In Name}/1.0

As described here. Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!