Oracle VM Consulting
view counter

Too Many Redirects When Cookies Are Not Enabled

Thanks to Joel Kallman for this story

A person (Wouter Verkuijl) was kind enough to post on my blog, not only the problem he encountered when accessing Oracle Learning Library mobile from his iPad, but also the actual problem.  If you access Oracle Learning Library (or any APEX 4.1 application) from a browser which does not accept cookies, you'll see the URL changing in the browser a number of times and then you'll get some nice message similar to:

Oracle Virtualization and Cloud Consulting
view counter
Of course, the Oracle Learning Library team then asked me "Any ideas on how we can trap the 310 HTTP error code (too many redirects) and provide a user-friendly message (e.g. Enable cookies) on how to resolve the problem?"  As it turns out, it's actually quite easy.
  1. The first step is ensuring that the page that is being accessed has the page attribute 'Authentication' set to 'Page is Public' instead of 'Page Requires Authentication' (thanks Christian).  Even if you are using an application which has an authentication scheme of "No Authentication (using DAD)", the specific page attribute 'Authentication' must still be set to 'Page is Public'.  This will stop APEX from doing a wild number of redirects if cookies are not enabled.
  2. Detecting if Cookies are Enabled in the Browser
    • Our preferred approach (thanks Anthony) is to do this via a dynamic action on the public page with the following attributes:
      • Advanced
      • Name: Cookies not enabled
      • Event: Page Load
      • Condition: JavaScript expression
      • Value: !navigator.cookieEnabled
      • True Action: Alert
      • Text: Cookies are not enabled! 
      • No False Action, leave blank.
    • Alternatively, you could solve this via JavaScript in the page header, with something as simple as the following code in the page attribute "Execute when Page Loads":
if (!(navigator.cookieEnabled)) {alert('Cookies are not enabled');}
By doing this via a dynamic action, you get the benefit of not only having the alert message be translatable, but this is also much easier to find and maintain in your application instead of having JavaScript sprinkled around your application.

I have to point out that you will need Application Express 4.1.1 to achieve this.  Application Express 4.1.1 was released on February 21, 2012.  The Oracle Learning Library team has already updated their application to take advantage of this.

Read the entire article at its source

view counter