Click here to Skip to main content
13,556,419 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Redirect URI cannot contain newline characters.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: Redirect URI cannot contain newline characters.



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

What I have tried:

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);
         }

 }
Posted 9-Nov-17 19:27pm
Updated 9-Nov-17 20:40pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Why u r redirecting exceptions from "Response.Redirect" method ? It should be some page name which shows error to the users of the application. That's the reason it is throwing error.

Response.Redirect(ex.Message);
  Permalink  
Comments
ADI@345 10-Nov-17 1:58am
   
so what would be the code for catch block..
ADI@345 10-Nov-17 1:58am
   
It work fine on localhost but getting error on server.
phil.o 10-Nov-17 2:27am
   
Then it means that you do not get to the catch block locally.
It means the part of the code in the try block causes some issue when exectuted on the server. My bets would be an incorrect connection string, or insufficient permissions set on the database server (when you execute your code locally, your user account is connecting to the db; when you execute your code from the server, the account running the service is connecting to the db; depending on the permissions, this can go sideways).
ADI@345 10-Nov-17 2:30am
   
finally i know why i get this error..thanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Put a break point[^] in the catch block and see what is the actual error message and try to correct it.
catch (Exception ex)
            {

HttpResponse.Redirect Method [^] is used to navigate to other page, it accepts the url as the argument, where as you have passing the exception error message, so the method will look for the page (url) which is not there eg,
Response.Redirect("object reference not set to an instance");
It should look something like
Response.Redirect("SomePage.aspx")

You shall show the error message in following ways,

catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('"+ex.Message+"');", true);
            }

or

Add a label control to your page and show the error information in the label as
Label1.Text = ex.Message;

or
Create an error page and load the information from query string as
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

protected void Page_Load(object sender, EventArgs e)
       {
           lblMessage.Text = Request.QueryString["Message"];

       }

using
catch (Exception ex)
           {
               Response.Redirect("ErrorPage.aspx?Message=" + ex.Message);
           }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03-2016 | 2.8.180515.1 | Last Updated 10 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100