Solved

How can I have page render first, then execute classic asp? (want to speed up page response)

Posted on 2009-04-10
15
312 Views
Last Modified: 2012-05-06
Hi,
I have an ASP page that processing a form's submit button. The ASP generates a bunch of emails based on controls selected on the form by the site visitor and also displays a confirmation page, e.g. "Thank you for your registration".

The problem is that the the Confirmation page is not served up to the visitor until all the ASP processing is complete and since this now includes sending emails, it is very slow (up to 60 seconds).

Does anyone know how I could force the confirmation message to show on the page *before* all the ASP processing occurs?

Thanks,
Gwenda
0
Comment
Question by:gwendaellwood
  • 5
  • 5
  • 4
  • +1
15 Comments
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24119451
what email processing are you using?
Should not take no 60 seconds to process a page and send an email
Unless you are sending out a LOT of emails.

So.
It you are using a CDOSYS or equal mailing system.
Then the process is automatic on the visitor's end.
The only thing that would slow it down would be the way that you have it written up.

Carrzkiss
0
 
LVL 25

Assisted Solution

by:kevp75
kevp75 earned 20 total points
ID: 24120326
add a response.flush in before the email send code.
0
 
LVL 5

Assisted Solution

by:Abiel de Groot
Abiel de Groot earned 480 total points
ID: 24122555

You could also use the Queue method. If you do not all the emails are sent one by one and the web server has to negotiate with the smtp server for each send. The web server has to wait for a response from the mail server for each message. The Queue method simply put the messages in the mail servers Queue folder and thats it. By default the mail server will send messages from its queue folder in stacks of 50 so its much more efficient all round.

I use Persits asp mail, however, the queue folder method would exist for other mail sending components too.

Kind regards

A.
0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24122563
On my code it looks like this

Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Charset = "UTF-8"
Mail.ContentTransferEncoding = "quoted-printable"
Mail.Username = E_Email_UN
Mail.Password = E_Email_PW
Mail.Queue = True  '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< QUEUE
Mail.Host = E_SMTP_Server
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24122840
gwendaellwood,
What about it. Are you still experiancing this issue?
If so, please come back in and let us continue to help you.

Carrzkiss
0
 

Author Comment

by:gwendaellwood
ID: 24124194
hi carrzkiss , kevp75 and Jonbysoft and  thanks for the help. I'm going to move the code out of the <Head> section where it seems to get processed before the page is rendered. Then I'll put a response.flush at the top of the code to see if that makes the page appear before the code gets processed. Also I'll find out from the ISP if the mail object I'm using has a Queue (as in Mail.Queue=True like Jonbysoft's code), and if it does I'll try that first.

I've attached the slow running code as it is now
mail-code.txt
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24124291
To begin with.
You was creating to many IF Statements.
Doing
If
End if
Every one is a wayste of resources.
If
ElseIF
End IF
Will look at each one and resume next.

Example of your code changed to use the
ELSEIF

(Code untested)
The ELSEIF will not use up a lot of un-needed resources.

Good Luck
Carrzkiss
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">
 

<head>

<%@ LANGUAGE = "VBSCRIPT" %>

<%
 

dim strThankYouMsg

dim strLocalContactName

dim strLocalContactEmail

dim strLocalContactSubject 

dim strSelections

dim xmlhttp
 
 

'do a bunch of processing here to develop a string of selections from the form
 

'

' city list

if request.form("barrie")= "ON" then 

	strLocalContactName = "name"

	strLocalContactEmail= "whatever@whatever.ca"

	strLocalContactSubject = "Please send me Barrie local notices"

	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)

elseif request.form("calgary")= "ON" then 

	strLocalContactName = "name"

	strLocalContactEmail= "whatever@whatever.ca"

	strLocalContactSubject = "Please send me Calgary local notices"

	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)

elseif request.form("halifax")= "ON" then 

	strLocalContactName = "name"

	strLocalContactEmail= "whatever@whatever.ca"

	strLocalContactSubject = "Please send me Halifx local notices"

	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)

elseif request.form("montreal")= "ON" then 

	strLocalContactName = "name"

	strLocalContactEmail= "whatever@whatever.ca"

	strLocalContactSubject = "Please send me Montreal local notices"

	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)

elseif request.form("ottawa")= "ON" then 

	strLocalContactName = "name"

	strLocalContactEmail= "whatever@whatever.ca"

	strLocalContactSubject = "Please send me Ottawa area local notices"

	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
 

elseif request.form("toronto")= "ON" then 

	strLocalContactName = "name"

	strLocalContactEmail= "whatever@whatever.ca"

	strLocalContactSubject = "Please send me Toronto area local notices"

	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
 

elseif request.form("vancouver")= "ON" then 

	strLocalContactName = "name"

	strLocalContactEmail= "whatever@whatever.ca"

	strLocalContactSubject = "Please send me Vancouver local notices"

	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)

elseif request.form("winnipeg")= "ON" then 

	strLocalContactName = "name"

	strLocalContactEmail= "whatever@whatever.ca"

	strLocalContactSubject = "Please send me Winnipeg local notices"

	call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)
 

elseif request.form("ReferrerPage")="French" then

	stringPost = stringPost + "&group[1285177]=1"

	strThankYouMsg = "Votre information a été soumise. Vous recevrez une confirmation par courriel, " & _ 

	 "si vous avez donné votre adresse courriel. Vous recevrez dorénavant les avis. À noter que les avis locaux pourraient prendre jusqu'à 4 semaines avant de débuter."

	strThanks = "Merci"

else

	strThankYouMsg = "Your information has been submitted. You " & _

        "will receive a confirmation email shortly. " & _

        "You will begin receiving notices now. NOTE: Local notices may take up to 4 weeks to begin."

    strThanks = "Thank you"

end if
 
 

<%

Sub EmailLocalMailingList(strAddressee, strEmail, strSubject)

'SEND EMAIL CONFIRMATION TO LOCAL MAILING LIST CONTACT

	Set objMail = Server.CreateObject("SMTPsvg.Mailer")

		objMail.FromName = "Words Of Peace"

		objMail.FromAddress = "info@wordsofpeace.ca"

		objMail.RemoteHost = "mail.wordsofpeace.ca" ' Specify a valid SMTP server

		objMail.AddRecipient strAddressee , strEmail

		objMail.Subject = strSubject 
 

	txtBodyText =  _

		"Lastname: " & request.form("emma_member_name_last")  & VbCrLf & _

		"Firstname: " & request.form("emma_member_name_first")  & VbCrLf & _

		"Address: "  & rtrim(request.form("emma_member_street_address"))  & VbCrLf & _

		"City: "  & request.form("emma_member_city") & VbCrLf & _

		"Prov: "   & request.form("emma_member_province")  & VbCrLf & _

		"Postal Code: "  & request.form("emma_member_postal_code")  & VbCrLf & _

		"Email: " & request.form("emma_member_email") & VbCrLf & _

		"Phone: " & request.form("PhoneAreaCode") & " " & request.form("phone") & VbCrLf & VbCrLf & _

		strSelections

	

				

		objMail.BodyText = txtBodyText	

		objMail.SendMail 

		Set objMail = Nothing

end sub

%>

</head>

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:gwendaellwood
ID: 24124492
Carrzkiss - thank you for looking at my code.
The webiste visitor might choose more than option, tho, and your Elseif structure will go to Endif as soon as it encounters a True, meaning that it will stop processing as soon as it finds the first checkbox = "ON".
I haven't the other solutions yet but will try them tonight.
Gwenda
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24124592
humm. OK.

Let me know?

Carrzkiss
0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24125044
Hi gwendaellwood,

Firstly, yes... MOVE ALL THIS OUT OF THE HEAD!. The HEAD is the first part of the web page. You need all this happening before the web page is rendered. I'm thinking, the reason you put the code within the head was to catch foreign characters. However, if you start you VB code with the line

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

CODEPAGE="65001 will load the UTF character set which covers everything.


Secondly, the main reason you are getting a delay is this line.

call EmailLocalMailingList(strLocalContactName , strLocalContactEmail, strLocalContactSubject)

I am guessing the function EmailLocalMailingList() is actually sending the message. If you do not use a Queue method your web server will wait for a response from the mail server before proceeding to the next line of your code.

You are opening and closing the mail object each time rather than collecting a comma deliminated string Opening the mail object send all the emails and closing the mail object. In addition use the Queue method.

I often send email bulletins from my web applications, and sending 1 or a 500 takes nearly the same time!

0
 
LVL 5

Accepted Solution

by:
Abiel de Groot earned 480 total points
ID: 24125166
I would do it like this.

Kind regards

Abiel M de Groot Sanders

--------------------------------------------------------------------------------------------------------------------------------------------------------------
Start by changing the checkboxes so as they are all called the same think (EG chk_Cities) the value of each will be the city name. Then collect them as such:

SelectedCheckboxes = request.form("chk_Cities")

The FORM object only return checkboxes which have been checked, so you can expect back something like this

calgary, montreal,ottawa

They will automatically be comma deliminated.

Then send this string to the email script where you will convert it into a one dimensional array

call EmailLocalMailingList(SelectedCheckboxes)

Make another SUB where you place you variables into a select Case like this


--------------------------------------------------------
Sub ReturnMyVariables(PassedCity)
Select Case PassedCity
Case barrie
      strLocalContactName = "name"
      strLocalContactEmail= "whatever@whatever.ca"
      strLocalContactSubject = "Please send me Barrie local notices"

Case calgary
      strLocalContactName = "name"
      strLocalContactEmail= "whatever@whatever.ca"
      strLocalContactSubject = "Please send me Calgary local notices"

Case halifax
      strLocalContactName = "name"
      strLocalContactEmail= "whatever@whatever.ca"
      strLocalContactSubject = "Please send me Halifx local notices"

Case montreal
      strLocalContactName = "name"
      strLocalContactEmail= "whatever@whatever.ca"
      strLocalContactSubject = "Please send me Montreal local notices"

End Select
End Sub
I only put a few, you need all of them as above.
--------------------------------------------------------


We can now open the mail object loop over all the array from the check box send all the messages and close the mail object.

Sub EmailLocalMailingList(PassedString)

Dim Array cities, i

Arraycities = Split(PassedString,,)
If IsArray(Arraycities) Then

Call ReturnMyVariables(Arraycities(i)) set the correct variables for this email

Open Mail Object() Whichever you are using

For i = 0 To Ubound(Arraycities)
---------------------------------------------------

Put your mail sending script in here

---------------------------------------------------
NEXT

Close Mail Object()
End If


if request.form("ReferrerPage")="French" then
      stringPost = stringPost + "&group[1285177]=1"
      strThankYouMsg = "Votre information a été soumise. Vous recevrez une confirmation par courriel, " & _
       "si vous avez donné votre adresse courriel. Vous recevrez dorénavant les avis. À noter que les avis locaux pourraient prendre jusqu'à 4 semaines avant de débuter."
      strThanks = "Merci"
else
      strThankYouMsg = "Your information has been submitted. You " & _
        "will receive a confirmation email shortly. " & _
        "You will begin receiving notices now. NOTE: Local notices may take up to 4 weeks to begin."
    strThanks = "Thank you"
end if

End Sub

--------------------------------------------------------------------------------------------------------------------------------------------
0
 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 24125174
In the select case I forgot to put double commas round the city name. You need to do it as follows.
Case "barrie"
Case "calgary"


etc

0
 

Author Comment

by:gwendaellwood
ID: 24126905
Thank you Jonbysoft. One last question: - if I move this code out of <HEAD> where should I put it? I just put it there because I didn't know any better.
0
 

Author Closing Comment

by:gwendaellwood
ID: 31569074
Thank you!
0
 

Author Comment

by:gwendaellwood
ID: 24127367
Jonbysoft: I found the mail object i am using has a queue = true property - wow! THAT really helped too! Thx,G
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now