4

I have a sites page, and it seems to work fine from a functional perspective. It has a custom controller that retrieves some data from a custom object and the Contact object, displays the data to the user, and lets them submit an updated version of the data into another custom object.

But after a certain amount of time (24-48 hours), when I go to the page I get a 'Not Authorized message'. After much testing, and thinking it was a a problem with css/statis resources, I have now found that the problem seems to be with the controller (i.e. a page with no references to css/static resources still fails)

When I get the error, I can login to SF and simply view the apex controller class in the usual Setup - Develop - Classes interface, and the public sites page then works again for another 24-48 hours.

What am I missing here? I have different versions of the page setup with cache enabled, and with cache set to false - they all fail.

1
  • on your <apex:page> element do you have a cache setting?
    – Ryan Guest
    Commented Oct 29, 2012 at 22:10

2 Answers 2

5

In case anyone ends up here, I did finally work this out with help from this post: http://www.tgerm.com/2010/10/debugging-sites-authorization-required.html

I set up a debug page as described in the post, included it as a sites page, and when the page failed, this debug page finally revealed the error.

My controller class had a test method in it, which in turn was referencing a second class - and that second class was trying to update a field it wasn't allowed to when running as a Sites user. So for reasons that aren't clear to me, the controller work fine for a while, and the test ran fine when logged in, but at some point, it would error out, and I could only fix it by viewing the class while logged in...

I only worked this out by following the link above, and setting up a debug page that I could access as the Sites User, which finally showed me the error - every other debug method provided no information...

1
  • I ran into the same issue last summer (2015), and it took over a month to finally figure it out. It's a difficult error to find. Commented Jan 27, 2016 at 15:15
1

Is it possible the resource your dealing with has some sort of authentication required to load an element.

If so, than you would have a authentication cookie in your browser that would expire and not allow you to authenticate and load an element from the browser after some time.

Although I think authentication cookies expire faster than that.

1
  • I don't think so...it just happened again - didn't work on two different machines/os - I log into SF, view the controller, and now it works on both machines... Commented Oct 30, 2012 at 16:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .