How to solve Sharepoint CSOM HTTP Request Error 429?

ぃ、小莉子 提交于 2019-12-01 12:34:19

问题


The sharepoint often displays error 429 (Too many requests) and we have already taken all the actions described in the article below, but some requests continue to be blocked.

https://docs.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online

Our scenario involves a customized desktop application (add-in) for Word, Excel, Power Point and Outlook that accesses the Sharepoint through CSOM (with user's network credentials) and we already registered this Add-in through the "/_layouts/15/AppRegNew.aspx" page and decorated all of our requests with "NONISV|{OUR ORGANIZATION NAME}|{OUR ADDIN NAME}/1.0 ", as described in:

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


回答1:


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!



来源:https://stackoverflow.com/questions/48933045/how-to-solve-sharepoint-csom-http-request-error-429

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