如何使用C#来净化HTML页上输入? [英] How to use C# to sanitize input on an html page?

查看:170
本文介绍了如何使用C#来净化HTML页上输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有消毒的输入到html页面库或可以接受的方法?

在这种情况下,我有只是一个名字,电话号码和电子邮件地址的形式。

code必须是C#。

例如:

 <脚本的src ='bobs.js'>李四< / SCRIPT>中应该成为李四


解决方案

如果通过了​​sanitize你的意思是删除标记全部,科比引用的正则表达式的例子就是你想要的解决方案的类型。

如果你只是想确保code不乱用你的设计,并呈现给用户。您可以使用HttpUtility.HtmlEn code方法prevent免受!

Is there a library or acceptable method for sanitizing the input to an html page?

In this case I have a form with just a name, phone number, and email address.

Code must be C#.

For example:

"<script src='bobs.js'>John Doe</script>" should become "John Doe"

解决方案

If by sanitize you mean REMOVE the tags entirely, the RegEx example referenced by Bryant is the type of solution you want.

If you just want to ensure that the code DOESN'T mess with your design and render to the user. You can use the HttpUtility.HtmlEncode method to prevent against that!

这篇关于如何使用C#来净化HTML页上输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆