重定向 URI 不能包含换行符

ytbtagmy 2005-10-17 04:01:17
重定向 URI 不能包含换行符
代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient ;
using ynMedicalInfo.PubClass;

namespace ynMedicalInfo.hy.MemberCenter
{
/// <summary>
/// Modifyother 的摘要说明。
/// </summary>
public class Modifyother : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DdlClassid;
protected System.Web.UI.WebControls.TextBox TxtContact;
protected System.Web.UI.WebControls.TextBox TxtPublishtime;
protected System.Web.UI.WebControls.TextBox TxtImg;
protected System.Web.UI.WebControls.Button btnChoiceImg;
protected System.Web.UI.WebControls.TextBox TxtContent;
protected System.Web.UI.WebControls.Button btnSaveCont;
protected System.Web.UI.WebControls.Button btnReturn;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
protected System.Web.UI.WebControls.TextBox TxtTitle;
private string m_EnterpriseId;
private string m_otherId;
protected System.Web.UI.WebControls.DropDownList DdlNClassid;
private string m_Seque;


private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
m_otherId = Request.Params.Get("otherId");
m_Seque = Request.QueryString["Seque"];
m_EnterpriseId = Session["EnterpriseId"].ToString();
if(!Page.IsPostBack)
{
BindDdlClassid();
InitPage();
btnChoiceImg.Attributes.Add("onclick","getImg()");
}
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnSaveCont.Click += new System.EventHandler(this.btnSaveCont_Click);
this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
private void BindDdlClassid()
{
string StrSql = "SELECT * FROM class";
DataSet ds;
ds = DbOperate.ExecuteSqlDataAdapter(StrSql);
DdlClassid.Items.Add(new ListItem("",""));
foreach(DataRow dr in ds.Tables[0].Rows)
{
DdlClassid.Items.Add(new ListItem(dr["ClassName"].ToString(),dr["ClassId"].ToString()));
}
DdlClassid.Attributes.Add("onchange","changeClass(this.options[this.selectedIndex].value)");
}
private void InitPage()
{
string strNClassName;
DataTable dtNClassid;
string StrSql ="SELECT convert(char(10),Publishtime,20) as Publishtime,"+
" Title,Classid,NClassid,Contact,Img,Content"+
" FROM otherInfo" +
" WHERE Seque='" +m_Seque+"'" +
" AND otherId=" + m_otherId +
" AND EnterpriseId='" + m_EnterpriseId + "'";
DataTable dtotherInfo =new DataTable();
try
{
dtotherInfo = DbOperate.GetDataTable(StrSql);

if (dtotherInfo.Rows.Count <= 0)
{
return;
}
else
{
string strTitle = dtotherInfo.Rows[0]["Title"].ToString().Trim();
string strClassId = dtotherInfo.Rows[0]["Classid"].ToString().Trim();
string strNClassId = dtotherInfo.Rows[0]["NClassid"].ToString().Trim();
string strContact = dtotherInfo.Rows[0]["Contact"].ToString().Trim();
string strImg = dtotherInfo.Rows[0]["Img"].ToString().Trim();
string strContent = dtotherInfo.Rows[0]["Content"].ToString().Trim();
string strNSqlClass = "SELECT Nclassid,NclassName FROM nclass WHERE classid = " + strClassId;
//小类的处理
strNClassName = "";
dtNClassid = DbOperate.GetDataTable(strNSqlClass);
foreach(DataRow dr in dtNClassid.Rows)
{
if (dr["Nclassid"].ToString() == strNClassId)
{
strNClassName = dr["NclassName"].ToString();
}
DdlNClassid.Items.Add(new ListItem(dr["NclassName"].ToString(),dr["Nclassid"].ToString()));
}

dtNClassid.Dispose();
dtotherInfo.Dispose();
TxtTitle.Text = strTitle;
DdlClassid.SelectedValue = strClassId;
DdlNClassid.SelectedValue =strNClassId;
TxtContact.Text = strContact;
TxtImg.Text = strImg;
TxtContent.Text = strContent;
}
}
catch(Exception ex)
{
Response.Redirect("Error.aspx?ErrorInfo=" + ex.Message,true);
}
}
public void getNClass()
{
string strResponse=UiFunctions.getNClass("Form1","DdlNClassid","changeClass");
Response.Write(strResponse);
}
private void btnSaveCont_Click(object sender, System.EventArgs e)
{
try
{
int Classid = Convert.ToInt32( DdlClassid.SelectedItem.Value);
int Nclassid = Convert.ToInt32(Request.Params.Get("DdlNClassid"));

string StrSql="UPDATE otherInfo "+
"SET Title =" + SQLTool.toSQLVal(TxtTitle.Text)+ "," +
"ClassId=" + Classid+","+
"NClassId="+ Nclassid +","+
"Contact= " + SQLTool.toSQLVal(TxtContact.Text) +","+
"Img=" + SQLTool.toSQLVal (TxtImg.Text) + "," +
"Content=" +SQLTool.toSQLVal(TxtContent.Text)+
" WHERE Seque='" + m_Seque +"'" +
" AND EnterpriseId='" + m_EnterpriseId + "'"+
" AND otherId=" + m_otherId;

DbOperate.ExecuteModifySql(StrSql);
}
catch(Exception ex)
{
Response.Redirect("Error.aspx?ErrorInfo=" + ex.Message,true);
}
if (m_Seque=="1")
{
Response.Redirect("other1.aspx",true);
}
if (m_Seque=="2")
{
Response.Redirect("other2.aspx",true);
}
if (m_Seque=="3")
{
Response.Redirect("other3.aspx",true);
}

}

private void btnReturn_Click(object sender, System.EventArgs e)
{
if (m_Seque=="1")
{
Response.Redirect("other1.aspx",true);
}
if (m_Seque=="2")
{
Response.Redirect("other2.aspx",true);
}
if (m_Seque=="3")
{
Response.Redirect("other3.aspx",true);
}

}


}
}
...全文
1136 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
prince_y 2005-10-17
  • 打赏
  • 举报
回复
Response.Redirect("Error.aspx?ErrorInfo=" + ex.Message.Replace("\n",""),true);
应该是没有问题的,我上次和你同样的错误就是这样弄好的
ytbtagmy 2005-10-17
  • 打赏
  • 举报
回复
你要下班,我还得加班呢?
要不把你QQ留给我,我直接问你,可以吗?
这样还比较快点.
JzeroBiao 2005-10-17
  • 打赏
  • 举报
回复
要下班了,你那个底层睇唔到,好难帮你调试,又没注释...
ytbtagmy 2005-10-17
  • 打赏
  • 举报
回复
怪不得有人教我这样写,可是一直没用.
ytbtagmy 2005-10-17
  • 打赏
  • 举报
回复
现在还是错的,出错信息为:"指定的参数已超出有效值的范围。参数名: 0"

JzeroBiao 2005-10-17
  • 打赏
  • 举报
回复
因为是有时是中文.
Response.Redirect("Error.aspx?ErrorInfo=" + ex.Message.Tirm(),true);
这样写没用...URL不能识别.
还有要注意URL最长255字节(好像),所以太长也出错...
JzeroBiao 2005-10-17
  • 打赏
  • 举报
回复
Response.Redirect("Error.aspx?ErrorInfo=" + ex.Message.Tirm(),true);
这样写没用的.
Response.Redirect("Error.aspx?ErrorInfo=" + Server.UrlEncode(ex.Message));
ytbtagmy 2005-10-17
  • 打赏
  • 举报
回复
还有我把
Response.Redirect("Error.aspx?ErrorInfo=" + ex.Message,true);
改为:
Response.Redirect("Error.aspx?ErrorInfo=" + ex.Message.Tirm(),true);
也没用
ytbtagmy 2005-10-17
  • 打赏
  • 举报
回复
没有用,还是一样的问题!
ytbtagmy 2005-10-17
  • 打赏
  • 举报
回复
没事啦!!!
还是很谢谢你的!
JzeroBiao 2005-10-17
  • 打赏
  • 举报
回复
对不起,睇错了..
prince_y 2005-10-17
  • 打赏
  • 举报
回复
哈哈~~和我上次遇到的错误一样,你的错误信息ex.Message里含有换行符号,把换行符Replace掉就行了ex.Message.Replace("\n","")
ytbtagmy 2005-10-17
  • 打赏
  • 举报
回复
不是,出错信息为:"重定向 URI 不能包含换行符".并没的和URL相关啊!!!
JzeroBiao 2005-10-17
  • 打赏
  • 举报
回复
LZ是不是要URL编码?
-----------EXP---------------------------
Response.Redirect("test.aspx?Name=" +Server.UrlEncode("我的"));

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧