我把用户输入到一个文本区域,存储它,最终显示回给用户。
在我的视图(剃刀)我想做这样的事情…
@Message.Replace("\n","</br>")
这不工作,因为Razor Html Encodes默认。这是伟大的,但我想我的换行。
如果我这样做,我开放了XSS的问题。
@Html.Raw(Message.Replace("\n","</br>"))
处理这种情况的正确方法是什么?
解决方法
使用HttpUtility.HtmlEncode然后做替换。
@Html.Raw(HttpUtility.HtmlEncode(Message).Replace("\n","<br/>"))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。