[1.7.x] Fixed #23939 -- Moved session verification out of middleware.

https://code.djangoproject.com/ticket/23939