如果從數據庫中提取鏈接的名稱,是否應該調用Html.Encode方法來清除名稱?在ASP.NET MVC中構建ActionLinks時應該調用Html.Encode
例如:
Html.ActionLink(Model.PersonFromDB.FirstName,
"Action",
"Controller",
new RouteValueDictionary { { "id", Model.PersonFromDB.Id } },
null)
或:
Html.ActionLink(Html.Encode(Model.PersonFromDB.FirstName),
"Action",
"Controller",
new RouteValueDictionary { { "id", Model.PersonFromDB.Id } },
null)
它將使你想這樣做是爲了確保有<a>
和</a>
之間注入的頁面沒有危險串感標籤,但腳本和錨標籤之間的這種可執行文件?
我在發佈問題並標記答案後偶然發現此網站,但我認爲這有助於其他人偶然發現此問題:http://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet – 2010-02-18 20:36:14