0

We have a convoluted ASP.Net 2.0 situation I need to resolve. I haven't written code since around 2010, but I'm probably the only one at my company who has a shot at getting this working.

We have a legacy Windows 2003 webserver that we're going to replace. But our company website, two ClickOnce deployments and several internal utilities are running on it, and service cannot be interrupted. This website was written in ASP.Net 2.0 (vb.net codebehind). So we need to be able to migrate the site to a replacement server.

We set up a Windows 2012 server that we plan to use to host the old website until we develop a new one, at which time we'll continue the upgrade to the latest Windows Server platform.

In the midst of this process, major browsers began refusing less than TLS 1.2 protocol, which cannot be supported on Windows Server 2003. The problem showed itself when clients tried to submit a fillable contact form we have running. Form submission was refused due to the TLS issue.

So, we used our wildcard SSL certificate and bound it to the new 2012 server. A subdomain was created, called contact.ourdomain.com. We have a copy of our website running on the new server. All links to the contact form were updated to point to 'contact.ourdomain.com/contact.aspx', which is being hosted on the new server. So now the TLS issue is being avoided.

However, there is a problem with the form. When executed in Visual Studio, it works correctly. But once it is published to the new server, the form is not showing the confirmation dialog or redirecting to our home page. This means that once the form is filled out and you click Submit, it sends the email message and then just sits there. It doesn't show the dialog or redirect. So not only do clients end up submitting the form like 5 times, they don't even know if it worked. How do I force this code to run to completion?

Any possible way to resolve this issue is fine. Javascript, whatever. This is a temporary fix and I just need it to work till the end of the year; the move to the new server will be finished by then.

'''Imports System.Net.Mail

Partial Public Class Contact Inherits System.Web.UI.Page Public StrPubMessage As String Public BlnReady As Boolean

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        lblMsgBox.Visible = False
    Else

    End If
End Sub

Public Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click

    Try
        ' validate the Captcha to check we're not dealing with a bot

        Dim isHuman As Boolean = frmCaptcha.Validate(txtCaptchaCode.Text)
        txtCaptchaCode.Text = Nothing

        If Not isHuman Then
            MsgBox("Please enter Captcha code.", MsgBoxStyle.OkOnly, "LDC Website")

        Else

            Dim emailclient As New SmtpClient("smtp.office365.com")
            emailclient.EnableSsl = True
            emailclient.Credentials = New System.Net.NetworkCredential("notifications@Ourdomain.com", "Our_Domain2020")


            Dim toEmailAddress As New MailAddress("email@Ourdomain.com")
            Dim fromEmailAddress As New MailAddress("notifications@Ourdomain.com")
            Dim emailMessage As New MailMessage(fromEmailAddress, toEmailAddress)
            Dim messageString As String

            emailMessage.IsBodyHtml = False
            emailMessage.BodyEncoding = System.Text.Encoding.UTF32

            emailMessage.Subject = "Message from website"

            messageString = "The following is an email inquiry from Ourdomain.com:" & vbCrLf + Chr(13) + Chr(10)
            messageString = messageString + "Name:                = " + txtName.Text & vbCrLf
            messageString = messageString + "Company Name:        = " & txtCoName.Text & vbCrLf
            messageString = messageString + "EMAIL:               = " & txtEmail.Text & vbCrLf
            messageString = messageString + "General Comment" & vbCrLf & vbCrLf & txtComment.Text & vbCrLf
            messageString = messageString + "End of inquiry." & vbCrLf & vbCrLf

            emailMessage.Body = messageString

            emailclient.Send(emailMessage)

            MsgBox("Your message was successfully transmitted to our team." _
                   & vbCrLf & "You will be contacted within 1 business day." _
                   & vbCrLf & "Thank you for your inquiry.", MsgBoxStyle.OkOnly, "Our Website")
            Response.Redirect("https://www.Ourdomain.com", False)

        End If

    Catch ex As Exception

        MsgBox("Your message could not be sent due to an unknown error. Please try again.", MsgBoxStyle.OkOnly)
        Response.Redirect("https://www.Ourdomain.com", False)

    End Try

End Sub

End Class'''

Stephen Falken
  • 141
  • 1
  • 7
  • what does it show in the browser developer tools network tab? the `Response.Redirect` is supposed to reply with a 302 HTTP status – kshkarin Oct 25 '20 at 20:18
  • Thanks for the response. The submission was executed, and in the dev console the following error appeared: "Error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500 ScriptResource.axd:39:13" There is a BotDetect captcha component being used on this page, but I removed it with no effect, so that's not the source of the error. I don't know what 'script resource' it can't find. – Stephen Falken Oct 26 '20 at 13:04
  • So it seems it's not even getting through the form submission? Is it correct that when users submit the form there's no record of it on the server? – kshkarin Oct 26 '20 at 16:15
  • Also in the network tab when refreshing the page one of the downloaded resources should have an .axd extension, this SO might shed some more light https://stackoverflow.com/questions/7881470/sys-webforms-pagerequestmanagerservererrorexception-an-unknown-error-occurred-w – kshkarin Oct 26 '20 at 16:19
  • Thank you again, I really appreciate your input. The form IS submitted (I receive it correctly in my email), but there's no further action; the code seems to just stop executing after the sendmail function is called. I had originally placed the message box and redirect in a Finally clause, but it didn't work so I moved the whole thing into the Try-Catch. I don't know how to tell if there's a record on the server of the execution. I'll check the link you sent. – Stephen Falken Oct 27 '20 at 04:43
  • Well I'm coming up empty trying to ascertain the problem with this form. I cannot understand why it works in the development environment and not on the server. It has to be something to do with security but I can't figure out what. The 500 internal server error is obviously not telling me anything, and I don't know why the ASP error isn't showing up in the Event Viewer. The entire thing appears to be illogical, so I'm clearly missing some fundamental piece of the puzzle, I guess. I just don't know where to look for it. – Stephen Falken Oct 28 '20 at 19:30
  • The most straightforward solution is to log what's happening, even if it means to log after every critical operation, and then narrow it down to the lines of code that cause the 500 error, since you mentioned that the email is sent correctly then it could the next steps, possibly even the redirect line. – kshkarin Oct 28 '20 at 20:36
  • p.s. the `MsgBox` line, after the email send and before the redirect, shouldn't be on the server running in IIS, have you tried commenting it out? – kshkarin Oct 28 '20 at 20:51
  • I will look into the MSGBox line and logging. Thanks again! – Stephen Falken Oct 30 '20 at 00:23

0 Answers0