asp.net 电子邮件被多次发送,但在本地计算机上正常工作



所以我遇到了一个奇怪的问题。我的网站上有一些联系表格,我写进了一个html包含文件。当用户填写表单并单击提交时,我会执行一些 jquery 来对我的 ashx 处理程序页面执行异步请求。现在在我的本地机器上它可以工作,因为它应该所有代码都被命中一次,我收到 1 封电子邮件给自己。当我将代码放在我们的生产服务器上并填写联系表格时,我在不同的时间得到 3 或 4 份副本。奇怪的是,jquery只被击中一次,所以我知道它没有多次调用ashx页面。下面是我的代码:

function procContact() {
    if ($('#txtFname').val() == '' || $('#txtFname').val() == 'First Name' || $('#txtLname').val() == '' || $('#txtLname').val() == 'Last Name' || $('#txtEmail').val() == '' || $('#txtEmail').val() == 'Email' || $('#txtPhone').val() == '' || $('#txtPhone').val() == 'Phone' || isValidEmailAddress($('#txtEmail').val()) == false) {
        $('#dialog').html('Please fill in all fields before submiting this request.');
        $('#dialog').dialog('open');
    } else {
        $('#dialog').html('<div style="width: 100%; text-align:center;"><img src="images/loading.gif" /><br />One Moment While We Submit Your Request...</div>');
        $('#dialog').dialog('open');
        setTimeout(function () {
            sendReq();
        }, 1200);
    }
}
function sendReq() {
    $.ajax({
        url: 'Myhandler.ashx?function=contact&f=' + $('#txtFname').val() + '&l=' + $('#txtLname').val() + '&e=' + $('#txtEmail').val() + '&p=' + $('#txtPhone').val(),
        cache: false
    }).done(function (html) {
        if (html.indexOf("Success") != -1) {
            //Display thank you
            $('#dialog').html('Thank you for contacting the xxx and we will call you within 2 business days.');
        }
    });
}

现在 ASHX 的东西

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    If context.Request.QueryString("function") = "contact" Then
        doContact()
    End If
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    Get
        Return False
    End Get
End Property
Protected Sub doContact()
    Dim resp As String = ""
    Dim mbody As String = ""
    Dim auth As New System.Net.NetworkCredential("xxxx@example.com", "ThePassword")
    Dim mails As New System.Net.Mail.MailMessage()
    Dim mailc As New System.Net.Mail.SmtpClient
    Try
        mailc.Host = "TheSmtpServer"
        mailc.UseDefaultCredentials = False
        mailc.Credentials = auth
        'Email to xxx --------------------------------------------------------------
        mbody = ""
        mails = New System.Net.Mail.MailMessage("xxx@example.com", "xxx@example.com", "The Subject", mbody)
        mails.IsBodyHtml = True
        mailc.Send(mails)
        mails.Dispose()
        'End xxx Email ---------------------------------------------------------------------------------------------------------------------
        'Email to Customer --------------------------------------------------------------
        mbody = "the Body stuff"
        mails = New System.Net.Mail.MailMessage("xxx@example.com", "xxx@example.com", "The Subject", mbody)
        mails.IsBodyHtml = True
        mailc.Send(mails)
        mails.Dispose()
        'End Customer Email ---------------------------------------------------------------------------------------------------------------------
        resp = "Success"
    Catch ex As Exception
        resp = "Fail"
    End Try
    HttpContext.Current.Response.ContentType = "text/plain"
    HttpContext.Current.Response.Write(resp)
End Sub

这一点上,我很困惑为什么它只在生产时这样做。

提前致谢

iOS 和 android 等移动平台上的 Chrome 浏览器(可能还有其他浏览器)在简单地打开浏览器并访问它们时刷新所有打开的选项卡。 您是否有机会在移动浏览器上打开此页面,并且每次页面刷新时都会重新提交表单?

这可以解释为什么电子邮件在不同时间全天传播。

最新更新