我正在处理的.net应用程序在用户输入打开尖括号“&lt;”时遇到错误作为输入。特别是当他们想要某种html输入时,例如<a href="www.google.com">Google</a>
我在没有“&lt;”的情况下尝试了完全相同的输入一切都完全正常。正在从asp:TextBox
读取输入,并将其作为参数添加到SQL INSERT INTO语句中。我正在使用try catch块来捕获SqlException,但是当我将catch语句更改为catch(Exception err)
时,甚至都没有捕获到这个特殊问题。我知道“&lt;”用作SQL中的少于操作但是,它应该不是问题,因为输入是一个参数吧?为什么它只是“&lt;”而不是“&gt;”它们也在输入中,因为两个字符都是有效的SQL运算符?这是实际的代码片段。
try
{
SQL_Command.Connection = SQL_Connection;
SQL_Command.CommandText = "INSERT INTO tabl1 ([ID], [fName], [lName], [bio]) VALUES (@ID, @First, @Last, @Bio)";
SqlParameter ID, First, Last, Bio;
ID = new SqlParameter("@ID", id_text.Text);
First = new SqlParameter("@First", firstName_Text.Text);
Last = new SqlParameter("@Last", lastName_Text.Text);
Bio = new SqlParameter("@Bio", bio_Text.Text);
SQL_Command.Parameters.Add(ID)
SQL_Command.Parameters.Add(Last)
SQL_Command.Parameters.Add(First)
SQL_Command.Parameters.Add(Bio)
SQL_Command.ExecuteNonQuery();
}
catch (Exception err)
{
Response.Write(err);
}
此表的架构为:
ID int NOT NULL
fName nVarChar(255)
lName nVarChar(255)
bio nVarChar(MAX)
答案 0 :(得分:2)
您获得的错误消息很可能是ASP Net保护您的网站免受跨站点脚本攻击的结果。角括号的打开看起来很可疑,因为您可能会在页面上注入恶意javascript或HTML。此问题已在此链接中得到解答:A potentially dangerous Request.Form value was detected from the client
希望有所帮助!