本文介绍了重定向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 thisWhat 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); } } 推荐答案 catch (Exception ex) { HttpResponse.Redirect Method [ ^ ]用于导航到其他页面,它接受 url 作为参数,在此处传递异常错误消息,因此该方法将查找页面(url)哪个不存在,例如, Response.Redirect(对象引用未设置为实例); 应该看起来像 Response.Redirect(SomePage.aspx) 您将通过以下方式显示错误消息, 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); } 或 为页面添加标签控件并显示错误信息标签为 orAdd a label control to your page and show the error information in the label asLabel1.Text = ex.Message; 或 创建错误页面并将查询字符串中的信息加载为 orCreate 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"]; } 使用 usingcatch (Exception ex) { Response.Redirect("ErrorPage.aspx?Message=" + ex.Message); } 这篇关于重定向URI不能包含换行符。服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-26 21:42