Redirect URI cannot contain newline characters.

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
Anandita RaniAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
Response.Redirect(ex.Message);

what are you trying to redirect here? redirect without a valid URL will generate another error.
0
Anandita RaniAuthor Commented:
can you Provide me valid URL..
0
Ryan ChongCommented:
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).
0
Anandita RaniAuthor 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.
0
Ryan ChongCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.