我面临的问题在于我的形式我已经给出了必要的字段验证,并且它按照我的测试工作正常,但仍然接收带有空字段的背靠背电子邮件。我有文本框,用户必须填写他们的联系电话和提交我的邮件ID的表格。我已经测试了100次时间,如果数字字段为空,但每次都不接受表单提交,但我不知道为什么我收到空值的邮件。有没有可以克服验证的黑客攻击?以下是我正在使用的代码
<asp:TextBox ID="callBackNumber2" runat="server" CssClass="field-pitch" MaxLength="10"></asp:TextBox>
<asp:RequiredFieldValidator ID="r1" runat="server"
ControlToValidate="callBackNumber2" CssClass="validator"
ErrorMessage="Please enter call back number" style="position:relative;
top:-20px" ValidationGroup="callBack2"></asp:RequiredFieldValidator>
<span class="field-title">Nature Of Request</span>
<asp:DropDownList ID="callBackNature" runat="server" CssClass="field-pitch">
<asp:ListItem>Information about product</asp:ListItem>
<asp:ListItem>Need a Price Quote</asp:ListItem>
<asp:ListItem>Existing Order</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="makeCallBack2" runat="server" Text="Submit" CssClass="gen-button" ValidationGroup="callBack2" />
按钮单击事件
if (Page.IsValid) {
try {
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
mail.To.Add("main@abc.com");
mail.CC.Add("sample@abc.com");
mail.From = new MailAddress(mailTo.Text);
mail.Subject = "Call Back Request From " + callBackNumber2.Text + "";
mail.Body = "Call back Number - " + callBackNumber2.Text + "<br />Nature Of Request - " + callBackNature.SelectedItem.ToString + "<br />Source - " + Request.Url.AbsoluteUri + "<br />IP - " + ipaddress + "";
mail.IsBodyHtml = true;
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential(mailTo.Text, mailPassword.Text);
SmtpServer.Host = "relay-hosting.secureserver.net";
SmtpServer.EnableSsl = false;
SmtpServer.Send(mail);
mpCallBack.Show();
callBackResponse.Visible = true;
callBackContent.Visible = false;
} catch (Exception ex) {
Response.Write(ex);
}
}
答案 0 :(得分:0)
为什么不在代码的开头使用if子句,如下所示;
if (callBackNumber2.Text != string.Empty)
{ your codes }