利用方法HttpUtility.HtmlEncode来预处理用户输入

  利用方法HttpUtility.HtmlEncode来预处理用户输入。这样能阻止用户用链接注入JavaScript代码或HTML标记,比如//Store/Broswe?Genre=<script>window.location='www.kinpor.com'</script>

示例:

1 public string Broswe(string genre)
2 {
3     var message=HttpUtility.HtmlEncode("Store.Broswe, Genre = " + genre);
4     return message;
5 }

 

posted @ 2018-03-21 21:14  江城一枝花  阅读(178)  评论(0编辑  收藏  举报