【发布时间】:2013-07-06 02:45:59
【问题描述】:
我的代码如下:
Test.aspx:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<input type="text" value="<%=HttpUtility.HtmlEncode(ab)%>" runat="server"/>
</form>
</body>
</html>
Test.cs:
public partial class Test: System.Web.UI.Page
{
public string ab;
protected void Page_Load(object sender, EventArgs e)
{
ab = "<script>alert('111');</script>";
}
}
运行test.aspx页面后,文本框值为<%=HttpUtility.HtmlEncode(ab)%>
但是去掉runat="server"字符串显示正确!
【问题讨论】:
-
另见stackoverflow.com/questions/8725393/…。顺便说一句,您可以使用
标签: asp.net