We help IT Professionals succeed at work.

Redirect URI cannot contain newline characters.

Anandita Rani
Anandita Rani asked
on
protected void btnsave_Click(object sender, EventArgs e)
    {
        try
        {
            using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
            using (SqlCommand cmm = new SqlCommand())
            {
                cmm.Connection = cnn;
                cmm.CommandType = CommandType.Text;
                if (btnsave.Text == "Save")
                {
                    cmm.CommandText = "INSERT INTO register_user([name],[email],[email_pass],[panel_pass],[dept])" + "VALUES(@name,@email,@email_pass,@panel_pass,@dept)";
 
                    cmm.Parameters.AddWithValue("@name", txtname.Text.Trim().ToString());
                    cmm.Parameters.AddWithValue("@email", txtemail.Text.Trim().ToString());
                    cmm.Parameters.AddWithValue("@email_pass", txtemailpass.Text.Trim().ToString());
                    cmm.Parameters.AddWithValue("@panel_pass", txtpass.Text.Trim().ToString());
                    cmm.Parameters.AddWithValue("@dept", ddldept.Text.Trim().ToString());
                   
                }
 
                else
                {
                    cmm.CommandText = "UPDATE [register_user] SET name=@name,email=@email,email_pass=@email_pass,panel_pass=@panel_pass,dept=@dept where id=" + ViewState["id"];
 
                    cmm.Parameters.AddWithValue("@name", txtname.Text.Trim().ToString());
                    cmm.Parameters.AddWithValue("@email", txtemail.Text.Trim().ToString());
                    cmm.Parameters.AddWithValue("@email_pass", txtemailpass.Text.Trim().ToString());
                    cmm.Parameters.AddWithValue("@panel_pass", txtpass.Text.Trim().ToString());
                    cmm.Parameters.AddWithValue("@dept", ddldept.Text.Trim().ToString());
                   
                   
                 
                    }
                        cmm.Connection.Open();
                        cmm.ExecuteNonQuery();
                        cmm.Connection.Close();
 
                        ScriptManager.RegisterStartupScript(this, GetType(), "Success", "alert('Information Save Successfully.');", true);
                    gvbind();
                    clear();
                }
            }
            catch (Exception ex)
            {
                Response.Redirect(ex.Message);
            }
 
    }


I am getting this error when my file is on server ,in localhost my code work fine. Please provide me solution for this
Comment
Watch Question

Ryan ChongSoftware Team Lead

Commented:
Response.Redirect(ex.Message);

what are you trying to redirect here? redirect without a valid URL will generate another error.

Author

Commented:
can you Provide me valid URL..
Ryan ChongSoftware Team Lead

Commented:
can you Provide me valid URL..
this doesn't make sense. you got to know what you're going to do next after catching an exception, whether you're going to write the error message into a log file, or doing some redirection in your case (you got to provide and redirect to a page name).

Author

Commented:
I redirect to another another which is error page,now i do not get Redirect-URI-cannot-contain-newline-characters  error,  but i don't know my code work perfect locally , but give error on server.
Software Team Lead
Commented:
but i don't know my code work perfect locally , but give error on server.
try output the error message to a log file for debugging. there was some problem calling your stored procedure on your server.

a separate note, you should do redirection like:

Response.Redirect("yourErrorpage.aspx")

Open in new window


if you wish to pass the error message as querystring, you should encode it like;

Response.Redirect("yourErrorpage.aspx?err=" + System.Web.HttpUtility.UrlEncode(ex.Message));

Open in new window