diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php
index 5bc0556e7b96f7ad96e61ee014479a94c7dd9ebb..2af194976a4969f09e68842bf2d9a354204721b8 100644
--- a/module/VuFind/src/VuFind/Controller/MyResearchController.php
+++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php
@@ -66,6 +66,10 @@ class MyResearchController extends AbstractBase
 
         // Not logged in?  Force user to log in:
         if (!$this->getAuthManager()->isLoggedIn()) {
+            $this->followup()->store(
+                array(),
+                $this->getRequest()->getServer()->get('HTTP_REFERER')
+            );
             return $this->forwardTo('MyResearch', 'Login');
         }
 
@@ -165,8 +169,13 @@ class MyResearchController extends AbstractBase
      */
     public function logoutAction()
     {
+        $logoutTarget = $this->getRequest()->getServer()->get('HTTP_REFERER');
+        if (empty($logoutTarget)) {
+            $logoutTarget = $this->getServerUrl('home');
+        }
+
         return $this->redirect()
-            ->toUrl($this->getAuthManager()->logout($this->getServerUrl('home')));
+            ->toUrl($this->getAuthManager()->logout($logoutTarget));
     }
 
     /**
diff --git a/module/VuFind/src/VuFind/Controller/Plugin/Followup.php b/module/VuFind/src/VuFind/Controller/Plugin/Followup.php
index e4378db93fa05d0ac601d3fd594e7d4979dd9f20..d2d79771b12a9f7b1188b45d134bc1d6b24a7e8b 100644
--- a/module/VuFind/src/VuFind/Controller/Plugin/Followup.php
+++ b/module/VuFind/src/VuFind/Controller/Plugin/Followup.php
@@ -64,14 +64,17 @@ class Followup extends AbstractPlugin
      * Store the current URL (and optional additional information) in the session
      * for use following a successful login.
      *
-     * @param array $extras Associative array of extra fields to store.
+     * @param array  $extras      Associative array of extra fields to store.
+     * @param string $overrideUrl URL to store in place of current server URL (null
+     * for no override)
      *
      * @return void
      */
-    public function store($extras = array())
+    public function store($extras = array(), $overrideUrl = null)
     {
         // Store the current URL:
-        $this->session->url = $this->getController()->getServerUrl();
+        $this->session->url = !empty($overrideUrl)
+            ? $overrideUrl : $this->getController()->getServerUrl();
 
         // Store the extra parameters:
         foreach ($extras as $key => $value) {