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
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,251 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 55,601 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)));
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,066 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.

    0 comments No comments