Avoiding a redirect loop in ASP.NET MVC

Under certain conditions, I would like to redirect errors to the Home controller, but I want to make sure that I do not fall into the “redirection” cycle (an exception is thrown, each time leading to another redirection). What is the best way to do this?

+3
source share
3 answers

It looks like you are asking for a solution to the problem (for example, "I want to redirect myself to exceptions, but not if the subsequent call will always throw an exception").

The ban on research in this area (while the problem of stopping is not possible, you can eliminate quite a few cases with a certain analysis). I would say that it is best to do what firefox does, in any case, to keep track of how many self-redirects have occurred and stop being redirected if they exceed a certain score.

To do this, a parameter can be added that increases with each subsequent “redirecting an exception throw” and is compared with this parameter when deciding whether to redirect.

+3
source

, - . , , , , "" .

+1

The short response is not redirected to the home controller.

Instead, redirect to the static error message page.

It will be cleaner and more stable.

0
source

Source: https://habr.com/ru/post/1729446/


All Articles