Drupal 8 reset session each request I have create a EventSubscriber like this:

&lt;?php

namespace Drupal\custom_session\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpKernel\KernelEvents;

/**
 * Class SessionInitial.
 */
class SessionInitial implements EventSubscriberInterface {

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

    return $events;
  }

  /**
   * This method is called whenever the kernel.request event is
   * dispatched.
   *
   * @param GetResponseEvent $event
   */
  public function setSession(Event $event) {
    // Start request.
    kint($_SESSION['page']);
    $route_name = \Drupal::routeMatch()-&gt;getRouteName();
    if ($route_name == 'view.frontpage.page_1') {
      $_SESSION['page'] = 'Home page';
    }
    else {
      $_SESSION['page'] = 'Other page';
    }
    // End logic.
    kint($_SESSION['page']);
  }

}


Every request I'll check prev $_SESSION['page'] and process logic.

But each request $_SESSION['page'] all has same value Other page.  

Test step by step:

1, Go to home page (router name is **view.frontpage.page_1)**



2. Refesh browser with url home page but debug result is the same:



Also last request was set $_SESSION['page'] to Home Page. 
I don't know why. Someone can help me. Thanks!
With @4k4's suggestion, I found the problem. After each request has a ajax request. The request has route name is quickedit.attachments and method post. So I edited code like that:

public function setSession(Event $event) {
    $route_name = \Drupal::routeMatch()-&gt;getRouteName();
    if (!$event-&gt;getRequest()-&gt;isXmlHttpRequest()) {
      if ($route_name == 'view.frontpage.page_1') {
        $_SESSION['page'] = 'Home page';
      }
      else {
        $_SESSION['page'] = 'Other page';
      }
    }
  }


Now it's working good. Thanks!