I have inherited some JS code that is playing up. It looks something like this:

ExecuteOrDelayUntilScriptLoaded(MyFunc, "sp.js")
function MyFunc() {
  var ctx = new SP.ClientContext(servRelativeUrl);
  var web = ctx.get_web();
  var list = web.get_lists().getByTitle(listTItle);
  ctx.load(list, "EffectiveBasePermissions");
  ctx.executeQueryAsync(successFunc, failFunc);

The problem I am having, is that this code only works sometimes. If you have not been to the page for a few minutes, the code will almost always fail with UnauthorizedAccessException: You do not have permission to perform this action or access this resource. from the async call. If you have been to the page recently, the code works.

I can reproduce the error on two farms using the same code.

Edit: I have checked the logs on the WFEs. I can see the request happen. with an error message Unknown SPRequest error occured. More information 0x80070005 <GUID>

  • The ClientContext has a timeout feature, which is causing your problem. Unfortunately, I've never found a way to modify the timeout settings via code, it must be set globally on the server.
    – WhiteHat
    Commented Jul 31, 2015 at 0:35
  • Awesome! Any hints on the best steps to verify this is the problem?
    – Alex
    Commented Jul 31, 2015 at 0:38
  • Not at the moment. Maybe tomorrow when I get to work. All I know is, I wrote an extensive JavaScript library incorporating ClientContext. Due to this issue, I ripped it apart, replacing with REST and WebServices.
    – WhiteHat
    Commented Jul 31, 2015 at 1:02
  • Here's the reference for "sp.js": msdn.microsoft.com/en-us/library/office/…
    – WhiteHat
    Commented Jul 31, 2015 at 1:09

1 Answer 1


I've had this error too!

The way I fixed it was described on a blog by Wictor Wilén. The way he explains it is that there is a token on the SharePoint page that has a timeout. If the token has expired then you can no longer make valid calls.

Luckily you can refresh the token at any time

UpdateFormDigest(_spPageContextInfo.webServerRelativeUrl, _spFormDigestRefreshInterval);
  • This is a synchronous call, so no callbacks required
  • It only updates the token if required, so it is quite fast if your token hasn't expired

Blog: http://www.wictorwilen.se/sharepoint-2013-how-to-refresh-the-request-digest-value-in-javascript

  • Unfortunately, this did not work :(
    – Alex
    Commented Jul 31, 2015 at 2:00
  • @Alex sorry I just noticed you're using 2010. This solution might only apply for 2013 Commented Jul 31, 2015 at 2:03
  • @jasonscript - this solution is not working for me either. however i am using SharePoint 2013. Do you know any other way around ? Thanks in Advance.. Commented May 13, 2016 at 11:59
  • Sorry @RohitWaghela I don't have any other work-around. Did you try reading Wictor's blog - linked in answer? He provides a lot more information than I do here Commented May 16, 2016 at 1:00
  • Thanks @jasonscript. Wictor's blog helped me out to resolving this issue. My code is working fine, when refreshing the token as suggested in this blog. Commented May 16, 2016 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.