none
Reload queries/items after token expiry and 401 unauthorised error RRS feed

  • Question

  • HasPendingRequests flag is set to false, after every ExecuteQuery. This happens even if the ExecuteQuery returned '401 - Unauthorised'. The previously loaded items are dismissed and we have to re-load them. Is there any good way to re-execute the loaded query items? Calling a Load() again seems one option, but would like to know more options/ideas.

    ctx.Load(web.Lists);

    RetryCall();

    void RetryCall()

    {

    bool canRetry = true;

    while (canRetry) {

        try {

              ctx.ExecuteQuery();   // Assume this throws 401.

         } catch (Exception e) {

                 // Check to see what kind of error is and then set canRetry flag appropriately.

                 // If it returns 401, I want to retry after fetching the new access token. Am able to get the new token, but

                // have to reload items (i.e., ctx.Load(web.lists)). Any suggestions?

         }

    }

    }

    Sunday, February 19, 2017 4:29 PM

All replies

  • Hi Rajesh,

    Can you provide the complete code in use? Let’s see if there is any better way to handle the re-request.

    Best regards,

    Patrick

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, February 21, 2017 9:59 AM
    Moderator
  • Hi Rajesh,

    Any progress or have you found a better way?

    Best regards,

    Patrick


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, February 24, 2017 9:40 AM
    Moderator
  • Hi Patrick, I have to create this code file for you (removing some other code). Isn't that snippet easy to fit into any of your working samples?

    I see not much way than to reload in case of token expiry. The context seems to be having a opaque list of items and so can't really construct them again.

    Regards

    Rajesh.R

    Friday, February 24, 2017 3:16 PM
  • Hi Rajesh,

    How is the thing going now?

    I would say your code is already very straight forward and there seems no other better way to re-send the request.

    Anyway, I will keep an eye on this issue and come back if there is any finding.

    Best regards,

    Patrick

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, February 28, 2017 8:55 AM
    Moderator
  • Hi Patrick, the one way that helped was to reload the LINQ when the token has expired. I haven't found any solution thus far.

    Regards

    Rajesh.R

    Sunday, March 19, 2017 9:18 AM