Redirect URI cannot contain newline characters.

Jagjit Saini 106 Reputation points
2021-07-16T04:52:03.133+00:00

Hi

protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
if (exception != null)
{
HttpException httpException = null;
if (exception is HttpException)
{
httpException = exception as HttpException;
}

            Response.Clear();
            Server.ClearError();
            Response.Redirect(String.Format("~/Error/Index/?message={0}", exception.Message));
        }
    }

Thanks

ASP.NET MVC
ASP.NET MVC
A Microsoft web application framework that implements the model-view-controller (MVC) design pattern.
744 questions
No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 31,741 Reputation points
    2021-07-16T16:35:27.63+00:00

    In the following line

    Response.Redirect(String.Format("~/Error/Index/?message={0}", exception.Message));
    

    You need to url encode the message.

    Response.Redirect(String.Format("~/Error/Index/?message={0}", Server.UrlEncode(exception.Message)));
    

1 additional answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,026 Reputation points
    2021-07-16T09:52:12.317+00:00

    Hi @Jagjit Saini ,

    Redirect URI cannot contain newline characters.

    Where is the newline characters? I have tried the codes of Response.Redirect and it works fine.
    You could check which lines have errors.
    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.