我有一个非常烦人的问题,到目前为止我不知道如何解决。我正在使用 ASP.NET MVC 和 C# 构建一个向用户显示表格的网站。数据来自 MS SQL 数据库,我正在使用 MVCGrid.net 创建表。这是将在表中显示的列的示例:
cols.Add("note").WithHtmlEncoding(false)
.WithValueExpression(i => i.Notice)
.WithValueTemplate("{Value}<button class='btn btn-primary btn-block' data-target='#note-modal' data-record-id='{Model.ShipmentID}' data-note='{Value}' data-toggle='modal'><span class='glyphicon glyphicon-pencil'></span></button>")
.WithSorting(true)
.WithFiltering(true);
问题:当i.Notice
包含任何可能破坏我网站的 HTML 语法的字符时,我不知道有什么方法可以防止这种情况发生。我尝试使用WebUtility.HtmlDecode()
,但这并没有解决问题。如何确保我的网站上没有发生 HTML 注入或任何此类事件?