我的数据库中有一个文本有一个列,它有像这样的值
<br /><style><br /><!--<br />
现在当我试图在文本框中显示该值时,整个设计页面都会受到影响。 我的设计最初看起来像这样。
<tr>
<td width="590" colspan="2">
<div id="divBio" runat="server" style="margin-bottom: 0px; overflow: auto;
width: 400px; height: 50px" >
</div>
<asp:TextBox ID="txtBio" Style="overflow: auto" onchange="fnUpdate();" runat="server" Height="50px" Width="400px" Wrap="true" TextMode="MultiLine"></asp:TextBox></td>
</tr>
获取数据并在页面
中显示 <tr>
<td width="590" colspan="2">
<div id="divBio" runat="server" style="margin-bottom: 0px; overflow: auto;
width: 400px; height: 50px"><br /><style><br /><!--<br /></div>
<asp:TextBox ID="txtBio" Style="overflow: auto" onchange="fnUpdate();" runat="server" Height="50px" Width="400px" Wrap="true" TextMode="MultiLine"></asp:TextBox><br /><style><br /><!--<br /></td>
</tr>
知道为什么我的html设计会在文本框中显示此数据后发生变化
<br /><style><br /><!--<br />
答案 0 :(得分:1)
您正在将评论的开头添加到您的页面中,以便页面的其余部分被注释掉。将无法控制的数据插入页面时应该非常小心。开场评论非常无辜。假设黑客在数据库中创建了一个带有脚本标记和一些恶意脚本的条目。
您需要对数据进行html编码。
<%: db.myData %> // note the colon
// is short-hand for
<%= Server.HtmlEncode(db.myData) %>