防止跨站点脚本 C#

Preventing Cross Site Scripting C#

您好,我使用 HPE Fortify 扫描我的应用程序,它显示我的代码存在跨站点脚本漏洞。

如何防止基于以下代码的跨站点脚本?

LabelErrorResult.Text += "<li>Duplicate selection for sequence " + ddl.SelectedValue + "</li>";

使用 HtmlEncode 然后像

一样解码
String unsafevar = HttpContext.Current.Server.HtmlEncode("ddl.SelectedValue");

LabelErrorResult.Text += "<li>Duplicate selection for sequence " + HttpContext.Current.Server.HtmlDecode(usafevar); + "</li>";

更多可以访问msdn https://msdn.microsoft.com/en-us/library/w3te6wfz(v=vs.110).aspx