我有存儲在長相酷似該數據庫中的某些HTML:寫HTML頁面中的MVC 4
<strong><a href="http://www.google.com" target="_blank">Maintenance scheduled </a></strong>tomorrow
我想輸出正確格式爲HTML的Razor視圖。我不想看到<
和>
,我只想要HTML。
你可以從這個片段,我已經嘗試了幾種不同的東西看:
div id="maintenanceMessage">
@*@HttpUtility.HtmlDecode(sysSettings.MaintenanceMessage)*@
@*@HttpUtility.HtmlDecode((new HtmlString(sysSettings.MaintenanceMessage)).ToString())*@
@Html.Raw(sysSettings.MaintenanceMessage)
</div>
但在任何情況下它不斷顯示其文本:
<strong><a href="http://www.google.com" target="_blank">Maintenance scheduled </a></strong>tomorrow
,而不是格式化的HTML。 我不確定我在做什麼錯?
雖然需要小心使用,但如果內容是用戶生成的,您將被廣泛開放給XSS攻擊 – mxmissile
非常好。那就是訣竅。在這種情況下,只有最高級別的管理員才能訪問該字段,並且該消息只會顯示在網站的後端。但是,警告指出。謝謝! – jwatts1980