电子邮件地址验证为ASP.NET [英] Email Address Validation for ASP.NET

查看:105
本文介绍了电子邮件地址验证为ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你用什么来一个ASP.NET表单上验证一个电子邮件地址。我想,以确保它不包含XSS漏洞。

What do you use to validate an email address on a ASP.NET form. I want to make sure that it contains no XSS exploits.

这是ASP.NET 1.1

This is ASP.NET 1.1

推荐答案

发布的ASP.NET Web窗体上的任何脚本标签会导致您的网站,并抛出未处理的异常。

Any script tags posted on an ASP.NET web form will cause your site to throw and unhandled exception.

您可以使用正则表达式的asp验证程序以确认输入,只是确保你换你code后面的方法有,如果(IsValid的)条款的情况下,您的JavaScript被绕过。
如果您的客户端的JavaScript被旁路,脚本标签都贴到您的asp.net的形式,asp.net将抛出一个未处理的异常。

You can use a asp regex validator to confirm input, just ensure you wrap your code behind method with a if(IsValid) clause in case your javascript is bypassed. If your client javascript is bypassed and script tags are posted to your asp.net form, asp.net will throw a unhandled exception.

您可以使用这样的:

<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="tbEmail" ErrorMessage="Invalid Email Format"></asp:RegularExpressionValidator>

这篇关于电子邮件地址验证为ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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