【问题标题】:How to store HTML tags in SQL 2008 Simple (taking HTML code as input in textbox and stored it in database)如何在 SQL 2008 Simple 中存储 HTML 标签(将 HTML 代码作为文本框中的输入并将其存储在数据库中)
【发布时间】:2016-11-19 21:13:50
【问题描述】:

错误:

从客户端检测到有潜在危险的 Request.Form 值 (ctl00$ContentPlaceHolder1$htmlCode="table style="backgr...")

代码:

    SqlConnection n_con = new SqlConnection(constring);
    n_con.Open();
    string N_Query = "update imageAd set code = '"+textbox1.text+"' where id = '" + id + "'";
    SqlCommand N_cmd = new SqlCommand(N_Query, n_con);
    N_cmd.ExecuteNonQuery();

【问题讨论】:

  • 什么是SQL 2008 Simple
  • 了解参数化查询,尤其是在@jafarbtech 提到的关闭请求验证时

标签: sql asp.net sql-server


【解决方案1】:

在 .aspx 的 <%@ Page ... %> 指令中设置 validateRequest="false"

在 .NET 4 中,您可能需要做更多工作。有时还需要在 web.config 中添加<httpRuntime requestValidationMode="2.0" />

注意:但这会导致该页面中的脚本注入和Sql注入攻击。这就是为什么它显示“潜在危险”。为防止它在显示您从该页面获得输入的 html 时使用Lbel1.Text = Server.HtmlEncode(TextBox1.Text)。如果您在网页的管理端使用,您可以协商它

【讨论】:

  • 呃,这个查询是不是有一个巨大的 SQL 注入漏洞,在你的回答中不值得一提吗?
猜你喜欢
  • 2013-08-27
  • 1970-01-01
  • 2011-04-26
  • 1970-01-01
  • 2021-08-05
  • 2011-08-12
  • 1970-01-01
  • 1970-01-01
  • 2011-05-14
相关资源
最近更新 更多