重定向URI不能包含换行符。服务器错误 [英] Redirect URI cannot contain newline characters. Server error

查看:85
本文介绍了重定向URI不能包含换行符。服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.







当我的文件在服务器上时,我收到此错误,在localhost我的代码工作正常。请为我提供解决方案



我尝试过:






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

 }

推荐答案

为什么要从响应重定向异常。重定向方法?它应该是一些页面名称,它向应用程序的用户显示错误。这就是它抛出错误的原因。


Response.Redirect(ex.Message);
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);


放一个破发点 [ catch ^ ] c $ c>阻止并查看实际的错误消息是什么并尝试纠正它。

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 [ ^ ]用于导航到其他页面,它接受 url 作为参数,在此处传递异常错误消息,因此该方法将查找页面(url)哪个不存在,例如,

Response.Redirect(对象引用未设置为实例);

应该看起来像

Response.Redirect(SomePage.aspx)



您将通过以下方式显示错误消息,< br $>



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


这篇关于重定向URI不能包含换行符。服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆