When an anonymous user hits '/user/login' route, how can I trigger an event? I want to trigger an event when an anonymous user comes to /user/login. I made an event subscriber, but it only fires one time:

namespace Drupal\mymodule\EventSubscriber;

use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\Core\Routing\TrustedRedirectResponse;

/**
 * Class LoginSubscriber.
 *
 * @package Drupal\mymodule\EventSubscriber
 */
class LoginSubscriber implements EventSubscriberInterface {

  /**
   * Redirect the user before we let them access a login form.
   */
  public function onLoginRequest(GetResponseEvent $event) {
    $account= \Drupal::currentUser();

    $config = \Drupal::config('mymodule.settings');
    $base_url = \Drupal::request()-&gt;getSchemeAndHttpHost();
    $site_key = $config-&gt;get('eweb_site_key');

    switch ($config-&gt;get('mode')) {
      case 'test':
        $url = $config-&gt;get('eweb_base_test');
        break;

      case 'live':
        $url = $config-&gt;get('eweb_base_live');
        break;

      default:
        $url = $config-&gt;get('eweb_base_test');
        break;
    }

    // User is accessing login page, check for active session
    if ($event-&gt;getRequest()-&gt;getRequestUri() == '/user/login' &amp;&amp; $account-&gt;isAnonymous() &amp;&amp; $event-&gt;getRequest()-&gt;query-&gt;get('loginFailed') == FALSE) {
      $response = new TrustedRedirectResponse($url . '/StartPage.aspx?Site=' . $site_key . '&amp;URL_success=' . $base_url . '/user/netforum/{token}&amp;URL_failed=' . $base_url . '/user/login?loginFailed=true');
      return $response-&gt;send();
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = ['onLoginRequest'];
    return $events;
  }
}


The purpose is that the external site will look to see if this user has an active session, if so, it will redirect back to my site with a token and that controller will handle logging in that user with some logic and user_login_finalize.

However, it is currently only firing once.
I agree with @Berdir, it shouldn't be a problem if the internal page cache stores a response for each query string.

But the issue here is probably that TrustedRedirectResponse is a cacheable response. When you use such a cacheable response you  have to add the correct cache metadata for the content of the response, here a context for the query arg:

  if ($event-&gt;getRequest()-&gt;getRequestUri() == '/user/login' &amp;&amp; $account-&gt;isAnonymous() &amp;&amp; $event-&gt;getRequest()-&gt;query-&gt;get('loginFailed') == FALSE) {

    $response = new TrustedRedirectResponse($url . '/StartPage.aspx?Site=' . $site_key . '&amp;URL_success=' . $base_url . '/user/netforum/{token}&amp;URL_failed=' . $base_url . '/user/login?loginFailed=true');

    $cache_metadata = new CacheableMetadata();
    $cache_metadata-&gt;setCacheContexts(['url.query_args:loginFailed']);
    // or set max-age = 0 instead
    // $cache_metadata-&gt;setCacheMaxAge(0);
    $response-&gt;addCacheableDependency($cache_metadata);

    $event-&gt;setResponse($response);

    }
  }


Then the dynamic page cache will vary by this context. Or add max-age = 0 to disable the dynamic page cache, because caching won't help here much, this is already cached for anonymous users.