hello i will get access few parameters from one web form to another one and i have used:
Response.Redirect("adpreview.aspx?email=" + txtEmail.Text + "&title=" + txtTitle.Text + "&message=" + lblResult.Text);
but i get this error: System.ArgumentException: Redirect URI cannot contain newline characters.
i reduced it to: Response.Redirect("adpreview.aspx?message=" + lblResult.Text);
but i got the same error... ???!!! how should i do? thanks your respond. kind regards

Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted Jul 16, 2023, 2:08 AM EDT
Hi venus
To resolve this issue, you can encode the query string parameters before appending them to the Redirect URI. Here's an example of how you can achieve this using the
HttpUtility.UrlEncodemethod in ASP.NET:string email = HttpUtility.UrlEncode(txtEmail.Text); string title = HttpUtility.UrlEncode(txtTitle.Text); string message = HttpUtility.UrlEncode(lblResult.Text); string redirectUrl = "adpreview.aspx?email=" + email + "&title=" + title + "&message=" + message; Response.Redirect(redirectUrl);By applying
HttpUtility.UrlEncodeto each query string parameter, any special characters or newline characters will be properly encoded, ensuring that the Redirect URI does not violate the URI syntax.if the answer helped kindly accept thanks
Amit MohantyRank #112 · 20K reputationPosted Jul 17, 2023, 2:05 AM EDT
The error message you're encountering suggests that the Redirect URI you're using contains newline characters, which are not allowed. This is likely caused by the value of the lblResult.Text parameter in your code.
string email = HttpUtility.UrlEncode(txtEmail.Text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "")); string title = HttpUtility.UrlEncode(txtTitle.Text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "")); string message = HttpUtility.UrlEncode(lblResult.Text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "")); Response.Redirect("adpreview.aspx?email=" + email + "&title=" + title + "&message=" + message);