I have a ashx handler in "_layouts/ihandler/.." in which I make AJAX requests for an in page search.

If my page stands still for to long the requests change from 200 to 401 return status, this is even if I keep making AJAX requests, as it only appears to go away on a page refresh.

Ajax request via GET returns correctly formed JSON with Error 200 when: - Page is freshly refreshed - Page has been standing for under a couple of minutes

Ajax request via GET returns correctly formed JSON with Error 401 when: - Freshly deployed and page not refreshed (Expected) - Page has stood still and not refreshed for a couple of minutes but still returns results - Page has been used only for Ajax requests and has not been a refreshed for a couple of minutes but still returns results

This is something I have not dealt with before, and I cannot find a reason for returned results on a 401 and I cannot also find out how to keep the 401s from happening.


Added that calls are using GET

Returns JSON

  • 1
    What exactly does your ashx handler return? Is it a javascript code or json or something else? What kind of code do you run inside the handler? Commented Sep 10, 2012 at 20:07
  • 1
    What request type? POST or GET?
    – eirikb
    Commented Sep 11, 2012 at 8:35

1 Answer 1


It is difficult to point out the exact reason for the issue. Here are som thougts which maybe can help you finding the solution:

I have some posts about httphandlers in sharepoint on my blog, among them an answer on sharepoint.stackexchange: How to access a Web application/Farm level property bag via jQuery/Javascript/ClientContext

Take a look on some built-in ashx-files in SharePoint, like scriptresx.ashx

Do you get 401 error there? When I try this, my page can stand still very long and I still get 200 status when I invoke


Rev must be changed in order to ajax call to invoked and retrieved from cache. See the picture. After 19 minutes it is still 200.

enter image description here

But I have encountered 401 errors in custom web services when something was not configured correctly.

Hope it helps.

  • I really love the post on your site about localisation, however the issue is the timeout scenario, this says to me the configuration is fine (Maybe?) I will look at the built in handlers and get back to you.
    – Hugh Wood
    Commented Sep 11, 2012 at 8:36
  • 1
    Very nice and complete answer
    – Remko
    Commented Sep 12, 2012 at 11:29
  • Hi Anatoly, the 401 still appears after a couple of minutes of idle time, but still returns results, this is the main thing that confuses me, the built in js files don't ever 401 so at least I have narrowed it down, thank you.
    – Hugh Wood
    Commented Sep 13, 2012 at 7:59
  • 1
    Fine, that it has been narrowed down. It is really strange that it is 401 (unathorized) error but results are still returned. What can be in the code which can time out and make a request unauthorized? Commented Sep 13, 2012 at 10:06
  • Nothing as far as I know, it pulls back data from a list which there is no user restrictions on. However no errors have been reported from the wild server, not a single 401 has come back from the tests, however it happens on local dev, test, the companies dev and their staging but live does not show the errors. JQuerys no cache works like the rev counter it seems also, but to no avail. Points awarded abound!
    – Hugh Wood
    Commented Sep 14, 2012 at 12:51

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.