Workaround for repeatedly call Response.Redirect and returns ERR_TOO_MANY_REDIRECTS

The “ERR_TOO_MANY_REDIRECTS” error occurs when the browser detects that it is being redirected in a loop. This can happen when a web page calls the Response.Redirect method multiple times without breaking the loop.

One workaround to fix this issue is to use a flag variable to check if the page has already been redirected. If the page has been redirected, the flag variable is set and the Response.Redirect method is not called again.

Here’s an example:

bool redirected = false;

if (!redirected)
{
    redirected = true;
    Response.Redirect("newPage.aspx");
}

Another way to avoid this error is to use a Server.Transfer method instead of Response.Redirect. The Server.Transfer method transfers the execution of the current page to a new page, without the browser being aware of it.

Server.Transfer("newPage.aspx");

It’s important to note that using Server.Transfer method doesn’t change the URL in the browser and it doesn’t update the browser history.

It’s also worth checking if the redirect is necessary in the first place, and if not, remove the redirect statement.

Leave a Reply