protected function getBackURL(SS_HTTPRequest $request) {
      // Initialize a sane default (basically redirects to root admin URL).
      $controller = $this->getToplevelController();
      $url = method_exists($this->requestHandler, "Link") ?
            $this->requestHandler->Link() :
            $controller->Link();

      // Try to parse out a back URL using standard framework technique.
      if($request->requestVar('BackURL')) {
         $url = $request->requestVar('BackURL');
      } else if($request->isAjax() && $request->getHeader('X-Backurl')) {
         $url = $request->getHeader('X-Backurl');
      } else if($request->getHeader('Referer')) {
         $url = $request->getHeader('Referer');
      }

      return $url;
   }