Skip to content

Removed redundant POST request exclusion info #3883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cookbook/security/target_path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ the name of the firewall, defined in ``security.yml``). Upon a successful
login, the user is redirected to this path, as to help them continue from the
last known page they visited.

On some occasions, this is unexpected. For example when the last request
URI was an HTTP POST against a route which is configured to allow only a POST
method, the user is redirected to this route only to get a 404 error.
In some situations, this is not ideal. For example, when the last request
URI was an XMLHttpRequest which returned a non-HTML or partial HTML response,
the user is redirected back to a page which the browser cannot render.

To get around this behavior, you would simply need to extend the ``ExceptionListener``
class and override the default method named ``setTargetPath()``.
Expand Down Expand Up @@ -56,9 +56,10 @@ Next, create your own ``ExceptionListener``::
{
protected function setTargetPath(Request $request)
{
// Do not save target path for XHR and non-GET requests
// Do not save target path for XHR requests
// You can add any more logic here you want
if ($request->isXmlHttpRequest() || 'GET' !== $request->getMethod()) {
// Note that non-GET requests are already ignored
if ($request->isXmlHttpRequest()) {
return;
}

Expand Down