2

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.

[update]

Added that calls are using GET

Returns JSON

Hugh Wood
  • 6,285
  • 1
  • 26
  • 45

1 Answers1

2

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

$.getScript("/_layouts/scriptresx.ashx?culture=en-us&name=sp.res&rev=1");

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.

Anatoly Mironov
  • 5,750
  • 2
  • 29
  • 56
  • 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 Sep 11 '12 at 08:36
  • 1
    Very nice and complete answer – Remko Sep 12 '12 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 Sep 13 '12 at 07: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? – Anatoly Mironov Sep 13 '12 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 Sep 14 '12 at 12:51
  • Thank you. Nice that it doesn't appear on the live site. I hope our discussion here can be useful for other sharepointers today and tomorrow. – Anatoly Mironov Sep 14 '12 at 13:43