I am working on various bug fixes on a small website and one thing is really confusing me.
Is there an easy explanation as to why some pages will redirect to a login page instead of the actual destination... but only while using Chrome?
Example: This page is supposed to check input against our mailing list and either add the details or return a message saying they're already on the list. It works fine in IE (go figure) but when I try it in Chrome it redirects me to the account login page.
HTML:
<%# Page Language="VB" MasterPageFile="~/Standard-no-menu.master" AutoEventWireup="false" CodeFile="join-email.aspx.vb" Inherits="JoinEmail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
<style type="text/css"><!-- #import url("/update-details.css"); --></style>
<script type="text/javascript" language="javascript" src="js/JScript.js"> </script>
<script language="javascript" type="text/javascript">
function validateForm()
{
if (aForgotPwd.style.display != null && aForgotPwd.style.display.toString() != "none") {
var emailEle = document.getElementById("<%= txtEmail.ClientID %>");
emailEle.focus();
return false;
}
if(document.getElementById('<%= txtEmail.ClientID %>').value=="")
{
alert("Please enter a value in the field \"Email\".");
document.getElementById('<%= txtEmail.ClientID %>').focus();
return (false);
}
validemail=0;
var checkStr = document.getElementById('<%= txtEmail.ClientID %>').value;
for (i = 0; i < checkStr.length; i++)
{
if(checkStr.charAt(i)=="#")
validemail |= 1;
if(checkStr.charAt(i)==".")
validemail |= 2;
}
if(validemail != 3)
{
alert("Please enter a valid email address.");
document.getElementById('<%= txtEmail.ClientID %>').focus();
return (false);
}
if(document.getElementById('<%= txtFirstName.ClientID %>').value=="")
{
alert("Please enter a value in the field \"First Name\".");
document.getElementById('<%= txtFirstName.ClientID %>').focus();
return (false);
}
if(document.getElementById('<%= txtLastName.ClientID %>').value=="")
{
alert("Please enter a value in the field \"Last Name\".");
document.getElementById('<%= txtLastName.ClientID %>').focus();
return (false);
}
}
</script>
<h1>Join Global PC Mailing List
</h1>
<div class="update-message"><asp:Label ID="lblMessage" runat="Server"></asp:Label></div>
<asp:Panel ID="pnlCreateAccount" runat="server">
<div class="update-row">
<div class="update-mandatory">*</div>
<div class="update-label">Email Address:</div>
<div class="update-field"><asp:TextBox cssClass="textbox" ID="txtEmail" MaxLength="255" width="350" runat="server"></asp:TextBox><b><a id="aForgotPwd" href="/forgotten-password.aspx" style="display:none"> Forgot password?</a></b></div>
</div>
<div class="update-row">
<div class="update-mandatory"> </div>
<div class="update-label"> </div>
<div class="update-field">We will never give your email address to anyone. Read our <a runat="server" href="~/privacy.aspx">privacy policy</a></div>
</div>
<div class="update-row">
<div class="update-mandatory"> </div>
<div class="update-label">Company Name:</div>
<div class="update-field"><asp:TextBox cssClass="textbox" name="txtAccountName" ID="txtAccountName" MaxLength="40" width="350" runat="server"></asp:TextBox>
</div>
</div>
<div class="update-row">
<div class="update-mandatory">*</div>
<div class="update-label">First Name:</div>
<div class="update-field"><asp:TextBox cssClass="textbox" name="txtFirstName" ID="txtFirstName" MaxLength="255" width="350" runat="server"></asp:TextBox></div>
</div>
<div class="update-row">
<div class="update-mandatory">*</div>
<div class="update-label">Last Name:</div>
<div class="update-field"><asp:TextBox cssClass="textbox" name="txtLastName" ID="txtLastName" MaxLength="255" width="350" runat="server"></asp:TextBox></div>
</div>
<h1>Choose Your Email Subscriptions</h1>
<div class="update-row">
<div style="float:left">
<div class="update-mandatory"> </div>
<div class="update-label">Subscribe to General Newsletters:</div>
<div class="update-checkbox"><asp:CheckBox ID="chkGenernalNewsletters" runat="server"></asp:CheckBox></div>
</div>
</div>
<div class="update-row">
<div class="update-mandatory"> </div>
<div class="update-label"> </div>
<div class="update-field">
<div class="green-button">
<asp:LinkButton ID="btnRegister" OnClientClick="return validateForm();" AlternateText="Join Up" Text="Join Up" runat="server" />
</div>
</div>
</div>
</asp:Panel>
</asp:Content>
VB.NET
Imports DataAccessLayer
Imports System.Data
Imports System.Net
Imports System.Net.Mail
Imports com.verticalresponse.api
Partial Class JoinEmail
Inherits System.Web.UI.Page
Dim c As GPCUser
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Master.Page.Title += " | Register"
If TypeOf Session("Customer") Is GPCUser Then
c = CType(Session("Customer"), GPCUser)
'Response.Redirect("update-details.aspx")
Else
c = New GPCUser
End If
If c.AccountNo = 0 Or c.AccountNo = CInt(System.Configuration.ConfigurationManager.AppSettings("WebsiteAccount")) Then
Else
Response.Redirect("update-details.aspx")
Exit Sub
End If
If Not Page.IsPostBack Then
Dim dt As DataTable = Nothing
dt = SqlHelper.ExecuteDataset(System.Configuration.ConfigurationManager.AppSettings("dbConn"), "x_ww_spGetCustomer", Request("custID")).Tables(0)
If Not dt Is Nothing Then
If dt.Rows.Count > 0 Then
Dim dr As DataRow = dt.Rows(0)
txtAccountName.Text = dr("AccountName")
txtFirstName.Text = dr("FirstName")
txtLastName.Text = dr("LastName")
txtEmail.Text = dr("Email")
If Request("custID") > 0 Then
Dim subscriptions As ContactSubscriptions = New ContactSubscriptions(Request("custID"))
' chkComputerPromotions.Checked = subscriptions.IsComputerPromotions
'chkElectronicPromotions.Checked = subscriptions.IsElectronicPromotions
chkGenernalNewsletters.Checked = subscriptions.IsGenernalNewsletters
End If
End If
End If
End If
End Sub
Protected Sub btnRegister_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRegister.Click
' c.CreateCustomerDetails(txtAccountName.Text, txtFirstName.Text, txtLastName.Text, txtEmail.Text, txtAddress.Text, txtSuburb.Text, txtCityTown.Text, txtPostcode.Text, txtPhone.Text, txtMobile.Text, lstCountry.SelectedValue)
' c.GeneratedPassword = txtPassword.Text
' GPCUser.AddUpdateCustomer(c)
' ' Save the subscription details
'
'If Request("custID") > 0 and Request("AccNO") > 0 Then
Dim subscriptions As ContactSubscriptions = New ContactSubscriptions(Request("custID"))
'subscriptions.IsComputerPromotions = chkComputerPromotions.Checked
'subscriptions.IsElectronicPromotions = chkElectronicPromotions.Checked
subscriptions.IsGenernalNewsletters = chkGenernalNewsletters.Checked
subscriptions.Save()
'End IF
' Session("Customer") = c
'SendUpdateAccountEmailMessage(c.EmailCount)
'ClientScript.RegisterClientScriptBlock(Me.GetType(), "Thanks", "alert('Your Website PC account has been created. ');", False)
If chkGenernalNewsletters.Checked = True Then
Dim listID As Integer = 284662333
Dim isMember As Boolean = False
Dim newSession As New loginArgs()
newSession.username = "Not Relevant"
' Your VerticalResponse username
newSession.password = "Not Relevant"
'Your VerticalResponse password
' objLA.impersonate_user = "subaccount#emailaddress.com"; // If accessing or acting as a subaccount, uncomment this and replace it with the applicable email address.
newSession.session_duration_minutes = "120"
Dim [date] As DateTime = DateTime.Now
' This is generated by creating a Service Reference that points to the VerticalResponse WSDL.
Dim VRUser As New VRAPI()
' Let's try to log in. The login call will return a session ID, which we will use in all subsequent calls.
Dim sessionId As String = Nothing
Try
sessionId = VRUser.login(newSession)
Catch ex As System.Exception
lblMessage.Text = ex.ToString()
End Try
Dim getMember As New getListMemberByEmailAddressArgs()
getMember.session_id = sessionId
getMember.list_id = listID
getMember.email_address = txtEmail.Text
Try
VRUser.getListMemberByEmailAddress(getMember)
isMember = True
Catch ex As System.Exception
isMember = False
End Try
If (isMember = False) Then
Dim nMember As New ListMember()
nMember.list_id = listID
Dim memberData As NVPair() = New NVPair(2) {}
memberData(0) = New NVPair()
memberData(0).name = "email_address"
memberData(0).value = txtEmail.Text
memberData(1) = New NVPair()
memberData(1).name = "first_name"
memberData(1).value = txtFirstName.Text
memberData(2) = New NVPair()
memberData(2).name = "last_name"
memberData(2).value = txtLastName.Text
nMember.member_data = memberData
Dim objAL As New addListMemberArgs()
objAL.list_member = nMember
objAL.session_id = sessionId
Try
VRUser.addListMember(objAL)
Catch ex As System.Exception
txtEmail.Text = ex.ToString()
End Try
Else
pnlCreateAccount.Visible = False
lblMessage.Text = "You are already on our mailing list."
Exit Sub
End If
End If
pnlCreateAccount.Visible = False
lblMessage.Text = "you have successfully subscribed to Website PC email database."
End Sub
<System.Web.Services.WebMethod()> _
Public Shared Function ValidateEmail(email As String) As String
Dim wbClient As WebClient = New WebClient()
Dim strUrl As String = ConfigurationManager.AppSettings("WebsiteURLFull") + "/ajax/check_email_address.aspx?Email=" + email
Dim reqHTML As Byte()
reqHTML = wbClient.DownloadData(strUrl)
Dim objUTF8 As UTF8Encoding = New UTF8Encoding()
Dim output As String = objUTF8.GetString(reqHTML)
If String.IsNullOrEmpty(output) Then Return String.Empty
Return output
End Function
Private Sub SendMessage(fromEmail As String, fromEmailName As String, _
toEmails As String(), IsBodyHtml As Boolean, message As String, subject As String)
Dim mail As MailMessage = New MailMessage
mail.From = New MailAddress(fromEmail, fromEmailName)
For Each toEmail As String In toEmails
mail.To.Add(New MailAddress(toEmail))
Next
mail.Bcc.Add(fromEmail)
mail.IsBodyHtml = IsBodyHtml
mail.Subject = subject
mail.Body = message
Dim s As New SmtpClient(System.Configuration.ConfigurationManager.AppSettings("MailServer"))
s.Send(mail)
End Sub
Private Sub SendUpdateAccountEmailMessage(emailCount As Integer)
Dim subject As String = "ALERT : Website user subscribed to email database"
Dim message As String
message &= "Via page join-email" & vbCrLf & vbCrLf
message += "Account No: " & Request("custID") & vbCrLf
message += "Email : " & txtEmail.Text & vbCrLf
message += "Account Name : " & txtAccountName.Text & vbCrLf
message += "First Name : " & txtFirstName.Text & vbCrLf
message += "Last Name : " & txtLastName.Text & vbCrLf
message += "Email : " & txtEmail.Text & vbCrLf
message += "Subscribe to General Newsletters : " & chkGenernalNewsletters.Checked & vbCrLf
'message += "Subscribe to Computer Promotions: : " & chkComputerPromotions.Checked & vbCrLf
'message += "Subscribe to Electronic Promotions: : " & chkElectronicPromotions.Checked & vbCrLf
message &= vbCrLf & vbCrLf
message += "Regards" & vbCrLf & vbCrLf & "WebsitePC Admin Team"
SendMessage(ConfigurationManager.AppSettings("AccountDetailsUpdateEmail"), "Website PC", _
New String() {ConfigurationManager.AppSettings("AccountDetailsUpdateEmail")}, False, message, subject)
End Sub
End Class
I'm attempting to implement Google's reCAPTCHA on a Classic ASP site and am attempting to follow the guidelines outline here:
https://developers.google.com/recaptcha/docs/asp
Following the instructions on that page, I've added this code to the top of the page that contains the form:
<%
recaptcha_challenge_field = Request("recaptcha_challenge_field")
recaptcha_response_field = Request("recaptcha_response_field")
recaptcha_public_key = "<font color=red>your_public_key</font>" ' your public key
recaptcha_private_key = "<font color=red>your_private_key</font>" ' your private key
' returns the HTML for the widget
function recaptcha_challenge_writer()
recaptcha_challenge_writer = _
"<script type=""text/javascript"">" & _
"var RecaptchaOptions = {" & _
" theme : 'red'," & _
" tabindex : 0" & _
"};" & _
"</script>" & _
"<script type=""text/javascript"" src=""http://www.google.com/recaptcha/api/challenge?k=" & recaptcha_public_key & """></script>" & _
"<noscript>" & _
"<iframe src=""http://www.google.com/recaptcha/api/noscript?k=" & recaptcha_public_key & """ frameborder=""1""></iframe><br>" & _
"<textarea name=""recaptcha_challenge_field"" rows=""3""cols=""40""></textarea>" & _
"<input type=""hidden"" name=""recaptcha_response_field""value=""manual_challenge"">" & _
"</noscript>"
end function
' returns "" if correct, otherwise it returns the error response
function recaptcha_confirm(rechallenge,reresponse)
Dim VarString
VarString = _
"privatekey=" & recaptcha_private_key & _
"&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _
"&challenge=" & rechallenge & _
"&response=" & reresponse
Dim objXmlHttp
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "POST", "http://www.google.com/recaptcha/api/verify", False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXmlHttp.send VarString
Dim ResponseString
ResponseString = split(objXmlHttp.responseText, vblf)
Set objXmlHttp = Nothing
if ResponseString(0) = "true" then
'They answered correctly
recaptcha_confirm = ""
else
'They answered incorrectly
recaptcha_confirm = ResponseString(1)
end if
end function
server_response = ""
newCaptcha = True
if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then
server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field)
newCaptcha = False
end if
%>
Also per that page, I've added this code to the form itself to generate the reCAPTCHA widget:
<% if server_response <> "" or newCaptcha then %>
<% if newCaptcha = False then %>
<!-- An error occurred -->
Wrong!
<% end if %>
<%=recaptcha_challenge_writer()%>
<% else %>
<!-- The solution was correct -->
Correct!
<%end if%>
I can get the CAPTCHA to display properly, but it isn't verifying - it will accept any answer including being left blank. I believe some of the code needs to be added to my script that actually handles the data, but am not sure which code or where to put it.
I've tried moving portions of the above code that appear to be for validation purposes to the script that processes the responses and generates an e-mail, but have had no luck there either.
The for page can be viewed here:
http://www.onlyproforma.com/mktimg/landingPage_ResultsFirst4_CAPTCHA.asp
I am aware there are other options, but I would like to get this one working if possible.
Any help is greatly appreciated.
I had a similar issue especially with the NEW reCAPTCHA tick functionality. If you look at the reCAPTCHA admin site which gives you your public and private (secret) keys, you'll see that the server side integration URL to verify, is different from the code above. In the code above, the verify URL is _http://www.google.com/recaptcha/api/verify whereas the verify URL supplied by the reCAPTCHA admin page is _https://www.google.com/recaptcha/api/siteverify. Very different.
Also, the parameters required are different. In the above code, there is a call for Request("recaptcha_challenge_field") and Request("recaptcha_response_field"). Yet the new reCAPTCHA verify only requires the response field. But even that has changed! It is now request.form("g-recaptcha-response").
Granted, the code that you are using above comes straight from Google themselves (https://developers.google.com/recaptcha/old/docs/asp). But it appears that this code is outdated, especially if you consider that it is filed in a directory called OLD.
So this is what worked for me!
Dim recaptcha_secret
recaptcha_secret = "your secret code"
Dim sendstring
sendstring = _
"https://www.google.com/recaptcha/api/siteverify?" & _
"secret=" & recaptcha_secret & _
"&response=" & request.form("g-recaptcha-response")
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring , false
objXML.Send()
The code below reads the response from Google. The reply comes back as a JSON object, but I cannot read or process the JSON response on the server-side and I could not find an easy method.
So the workaround was to search for the string 'true'. If it returned TRUE (positive) then the reCAPTCHA was confirmed. If it does not return TRUE, then the response is essentially
FALSE and the reCAPTCHA was not submitted correctly.
It is ugly but it works:
if instr(objXML.responseText,"true") then
response.redirect "to an appropriate page"
else
response.redirect "to an appropriate page"
end if
Maybe there is a neater way to read the Google reply, but I have tested it and it works for me.
The full code then would look like this:
<%
Dim recaptcha_secret
recaptcha_secret = "your secret code"
Dim sendstring
sendstring = _
"https://www.google.com/recaptcha/api/siteverify?" & _
"secret=" & recaptcha_secret & _
"&response=" & request.form("g-recaptcha-response")
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring , false
objXML.Send()
if instr(objXML.responseText,"true") then
response.redirect "to an appropriate page"
else
response.redirect "to an appropriate page"
end if
%>
The following code will go in the page where the form is posted. i.e. in your case L_Landing_actionJCR.asp
<% if server_response <> "" then %>
Wrong!
<% else %>
Correct!
<% else %>
i try to make a gui (hta) which can install on a client, one or more printers from the printer server.
the problem is when i create the button "install", the function is executed on form load and not by clicking on the button.
i don't understand why. can you help me please?
<HTML>
<HEAD>
<TITLE>printer installation</TITLE>
<HTA:APPLICATION ID = 'AppBase'>
<script language="VBScript">
Dim WshNetwork, objPrinter, intDrive, intNetLetter
strComputer = "change_printer_server_name_or_ip"
strHTML = "<TABLE BORDER='0'>"
Set WshNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
strHTML = strHTML & "<TR><TD><input type='button' value='install printer' name='" & objPrinter.Name & "' onclick='" & installprinter(printname, printserver) &"'>" & objPrinter.Name & "</input></TD><TD>" & objPrinter.Location & "</TD><TD>" & objPrinter.portname & "</TD></TR>"
next
strHTML = strHTML & "</TABLE>"
DataArea.InnerHTML = strHTML
function installprinter(printname, printserver)
Set WshNetwork = CreateObject ("WScript.Network")
on error resume next
PrinterPath = "\\" & printserver & "\" & printname
WshNetwork.RemovePrinterConnection PrinterPath, true, true
WshNetwork.AddwindowsPrinterConnection (PrinterPath)
msgBox "L'imprimante a été installée avec succès"
end function
</script>
</HEAD>
<BODY>
<span id="DataArea"></span>
</BODY>
The load order of your page is important.
When you attempt to assign DataArea, the DOM is not yet initialised, so DataArea does not exist. Here is a simple example of how to invoke your code when the DOM is ready:
<html>
<head>
<title>printer installation</title>
<HTA:APPLICATION ID = 'AppBase'>
<script language="VBScript">
strHTML = "<TABLE BORDER='0'>"
strHTML = strHTML & "<tr><td>Testing</td></tr>"
strHTML = strHTML & "</TABLE>"
Function OnLoad()
DataArea.InnerHTML = strHTML
End Function
</script>
</head>
<body onload="OnLoad">
<span id="DataArea"></span>
</body>
</html>
Note the <body onload="OnLoad"> and the new Function OnLoad().
EDIT - Updated to include a function invoked from the generated html:
<html>
<head>
<title>printer installation</title>
<HTA:APPLICATION ID = 'AppBase'>
<script language="VBScript">
strHTML = "<TABLE BORDER='0'>"
strHTML = strHTML & "<tr><td><button onclick=""TestingFunction"">Testing</button></td></tr>"
strHTML = strHTML & "</TABLE>"
Function OnLoad()
DataArea.InnerHTML = strHTML
End Function
Function TestingFunction()
MsgBox("Hello")
End Function
</script>
</head>
<body onload="OnLoad">
<span id="DataArea"></span>
</body>
</html>
You are actually calling your installprinter routine when generating your HTML. Instead you need to format the HTML to be a valid call at the time the button is clicked. You want your eventual HTML to look like this:
<TR><TD><input type='button' value='install printer' name='PrinterName'
onclick='installprinter "PrinterName", "PCName"'>PrinterName</input></TD>
<TD>PrinterLoc</TD>
<TD>PortName</TD></TR>
Note that since you're calling a sub, you exclude the parentheses. It looks weird but that's the way VBScript works. So your code to generate a table row should go like this instead:
strHTML = strHTML & "<TR><TD><input type='button' value='install printer' name='" & _
objPrinter.Name & "' onclick='installprinter """ & objPrinter.Name & """, """ & _
strComputer & """'>" & objPrinter.Name & "</input></TD><TD>" & _
objPrinter.Location & "</TD><TD>" & objPrinter.portname & "</TD></TR>"
I am a running VB script with asp classic and I am getting the following error:
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'FormatDateTime'
/whatsnew/updated_pages_www.htm, line 52
I am trying to work out what is causing the error. Is there anything wrong with the format of the date in the csv file?
The date format is: 20090220122443
PAGE CODE BELOW:
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.CharSet = "UTF-8" %>
<%
pagetitle="What was published last week on casa.gov.au"
%>
<%
connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("/whatsnew/data")
set connect = Server.CreateObject("ADODB.connection")
connect.open connectString
selectSQL = "SELECT * FROM www.csv"
set www_RS = connect.execute(selectSQL)
%>
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"-->
<p class="breadCrm">Home <span>></span> What's New</p>
<!--<img src="/_lib/images/menu/yourarea.gif" alt="" width="891" /> -->
<div class="twoColumnRow">
<div class="twoColumnContent">
<div class="contentPad">
<!-- Start of main content -->
<p class="imageRight"> </p>
<h1><%=pagetitle%></h1>
<%
www_RS.MoveFirst
%>
<caption><h3>New or Amended on www.casa.gov.au</h3></caption>
<ul class="relatedInfoLinks">
<%
Dim pagecode, pagecode2, newfiledate, publisheddate, moddate, createddate, newfilediff, recently_published
pagecode = www_RS("PAGECODE").Value
While not www_RS.EOF
pagecode = www_RS("PAGECODE").Value
pagecode2 = Instr(pagecode,"PC_")
pagecode3 = Instr(pagecode,"~")
createddate = FormatDateTime(www_RS("CREATED_DATE").Value,1)
moddate = FormatDateTime(www_RS("MOD_DATE").Value,1)
publisheddate = FormatDateTime(www_RS("PUB_DATE").Value,1)
newfilediff = DateDiff("y",www_RS("CREATED_DATE").Value,www_RS("PUB_DATE").Value)
recently_published = DateDiff("y",www_RS("PUB_DATE").Value,dtNow)
if (pagecode2 = 1) and (pagecode3 = 0) and (recently_published < 8) then
%>
<li>
<%
Response.Write("<a href='http://casa.gov.au/scripts/nc.dll?WCMS:STANDARD::pc=" & pagecode & "'>" & www_RS("DESCRIPTION").Value & "</a>")
%>
<BR>
Last modified <%=publisheddate%>
<BR>
<%
if newfilediff < 8 then
%>
<span style="color:red">* This is a new page</span>
<%
end if
%>
</li>
<BR>
<%
end if
www_RS.MoveNext
Wend
%>
</ul>
<!-- End of main content -->
</div> <!-- end contentPad div -->
</div> <!-- end twocolumncontent div -->
<div class="twoColumnLinks">
<!--#INCLUDE VIRTUAL="/_lib/include/quicklinks.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/mylinks.htm"-->
</div> <!-- end twocolumnlinks div -->
</div> <!-- end twocolumnrow div -->
<!--#INCLUDE VIRTUAL="/_lib/include/footer.htm"-->
The FormatDateTime function requires a validly formatted date as the first parameter.
Depending on the date/time format used in your location, it will be something like this (example: US date format):
"02-20-2009 11:24:43 AM"
"02/20/2009 11:24:43 AM"
"02-20-2009 14:24:43"
"02/20/2009 14:24:43"
As a test, you can check the validity of a date like this:
d = CDate("02-20-2009 11:24:43 AM")
d = CDate("02/20/2009 11:24:43 AM")
d = CDate("02-20-2009 14:24:43")
d = CDate("02/20/2009 14:24:43")
Or, using IsDate:
b = IsDate("02-20-2009 11:24:43 AM")
b = IsDate("02/20/2009 11:24:43 AM")
b = IsDate("02-20-2009 14:24:43")
b = IsDate("02/20/2009 14:24:43")
In your case, your date string: "20090220122443" is a valid date/time, but it is not in a valid date/time format.
You could use a function to convert your date string into a valid format. Here is an example of some code to do the conversion.
strDate = "20090220122443"
wscript.echo "strConvertDateString(strDate) =" & strConvertDateString(strDate)
wscript.echo "dateConvertDateString(strDate)=" & dateConvertDateString(strDate)
wscript.echo
wscript.echo FormatDateTime(strConvertDateString(strDate),1)
wscript.echo FormatDateTime(dateConvertDateString(strDate),1)
wscript.echo
Function strConvertDateString (strDateString)
strConvertDateString = mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2)
End Function
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
The function strConvertDateString accepts a date/time string in your format and returns a string in a format acceptable to the FormatDateTime function.
The function dateConvertDateString accepts a date/time string in your format and returns a date (CDate), which is also acceptable to the FormatDateTime function.
The first one should work in most locations. The second might work better if there are issues with date conversions particular to your location. You should only need to implement and use one of these two functions.
In any case, depending on your location, you may need to edit the functions to adjust the way that mid() is used to compose the date/time string.
Note: This was written for testing in VBScript (cscript.exe). Copy/cut/paste the Function into your .asp file for use. Then use the function like this:
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
Edit:
Here is a more detailed explaination of how to add this function to your .asp page and how to use the function.
First, you need to add the function to your ASP page.
Edit your page.
Normally, function declarations are placed inside the <head> section like this:
<html>
<head>
...
...
<%
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
%>
</head>
<body>
...
<!-- there will be more <html> or <% asp code %> here ... -->
Or, inside the <body> section like this:
<html>
<head>
...
...
</head>
<body>
<%
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
%>
...
<!-- there will be more <html> or <% asp code %> here ... -->
In your case, it looks like the sections of the page that contain the <html>, <head>, </head>, and <body> tags could be contained in the included files. You can verify that by examining the files:
"/_lib/include/header.htm"
"/_lib/include/menu.htm"
So, in your case, you'll want to insert the function declaration into your page after the <!--#INCLUDE VIRTUAL= lines, like:
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"-->
<%
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
%>
Or, you could probably insert the function declaration into one of these files:
"/_lib/include/header.htm"
"/_lib/include/menu.htm"
Next, find the statements that are using VBScript date functions where you are currently passing dates formatted like this: "20090220122443"
That would be (most likely) all of these:
createddate = FormatDateTime(www_RS("CREATED_DATE").Value,1)
moddate = FormatDateTime(www_RS("MOD_DATE").Value,1)
publisheddate = FormatDateTime(www_RS("PUB_DATE").Value,1)
newfilediff = DateDiff("y",www_RS("CREATED_DATE").Value,www_RS("PUB_DATE").Value)
recently_published = DateDiff("y",www_RS("PUB_DATE").Value,dtNow)
and edit those statements to use the function to convert the dates, like this:
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
moddate = FormatDateTime(dateConvertDateString(www_RS("MOD_DATE").Value),1)
publisheddate = FormatDateTime(dateConvertDateString(www_RS("PUB_DATE").Value),1)
newfilediff = DateDiff("y",dateConvertDateString(www_RS("CREATED_DATE").Value),dateConvertDateString(www_RS("PUB_DATE").Value))
recently_published = DateDiff("y",dateConvertDateString(www_RS("PUB_DATE").Value),dtNow)
So, if the code you provided in your question is still correct and complete, here is the same code using the date conversion function:
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.CharSet = "UTF-8" %>
<%
pagetitle="What was published last week on casa.gov.au"
%>
<%
connectString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; DBQ=" & Server.MapPath("/whatsnew/data")
set connect = Server.CreateObject("ADODB.connection")
connect.open connectString
selectSQL = "SELECT * FROM www.csv"
set www_RS = connect.execute(selectSQL)
%>
<!--#INCLUDE VIRTUAL="/_lib/include/header.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/menu.htm"-->
<%
Function dateConvertDateString (strDateString)
dateConvertDateString = CDate(mid(strDateString,5,2) & "/" & mid(strDateString,7,2) & "/" & mid(strDateString,1,4) & " " & mid(strDateString,9,2) & ":" & mid(strDateString,11,2) & ":" & mid(strDateString,13,2))
End Function
%>
<p class="breadCrm">Home <span>></span> What's New</p>
<!--<img src="/_lib/images/menu/yourarea.gif" alt="" width="891" /> -->
<div class="twoColumnRow">
<div class="twoColumnContent">
<div class="contentPad">
<!-- Start of main content -->
<p class="imageRight"> </p>
<h1><%=pagetitle%></h1>
<%
www_RS.MoveFirst
%>
<caption><h3>New or Amended on www.casa.gov.au</h3></caption>
<ul class="relatedInfoLinks">
<%
Dim pagecode, pagecode2, newfiledate, publisheddate, moddate, createddate, newfilediff, recently_published
pagecode = www_RS("PAGECODE").Value
While not www_RS.EOF
pagecode = www_RS("PAGECODE").Value
pagecode2 = Instr(pagecode,"PC_")
pagecode3 = Instr(pagecode,"~")
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
createddate = FormatDateTime(dateConvertDateString(www_RS("CREATED_DATE").Value),1)
moddate = FormatDateTime(dateConvertDateString(www_RS("MOD_DATE").Value),1)
publisheddate = FormatDateTime(dateConvertDateString(www_RS("PUB_DATE").Value),1)
newfilediff = DateDiff("y",dateConvertDateString(www_RS("CREATED_DATE").Value),dateConvertDateString(www_RS("PUB_DATE").Value))
recently_published = DateDiff("y",dateConvertDateString(www_RS("PUB_DATE").Value),dtNow)
if (pagecode2 = 1) and (pagecode3 = 0) and (recently_published < 8) then
%>
<li>
<%
Response.Write("<a href='http://casa.gov.au/scripts/nc.dll?WCMS:STANDARD::pc=" & pagecode & "'>" & www_RS("DESCRIPTION").Value & "</a>")
%>
<BR>
Last modified <%=publisheddate%>
<BR>
<%
if newfilediff < 8 then
%>
<span style="color:red">* This is a new page</span>
<%
end if
%>
</li>
<BR>
<%
end if
www_RS.MoveNext
Wend
%>
</ul>
<!-- End of main content -->
</div> <!-- end contentPad div -->
</div> <!-- end twocolumncontent div -->
<div class="twoColumnLinks">
<!--#INCLUDE VIRTUAL="/_lib/include/quicklinks.htm"-->
<!--#INCLUDE VIRTUAL="/_lib/include/mylinks.htm"-->
</div> <!-- end twocolumnlinks div -->
</div> <!-- end twocolumnrow div -->
<!--#INCLUDE VIRTUAL="/_lib/include/footer.htm"-->
To give this a try, copy your current .htm file to something like whatever.htm. Then, replace (or edit) your current .htm with the code above.
Unfortunately, I don't have a way to test your complete ASP page.
If you still have problems with this, it would be very helpful if you could provide a copy of your actual .htm file, and a copy of the files: /_lib/include/header.htm, and /_lib/include/menu.htm
I am trying to learn asp.net, and have hit a problem early on.
I am attempting to connect to a database that I have create on Net Registry's Cloud Hosting.
I just receive a 500 error when i try to access the page.
(I am on a Mac as well if this matters at all.)
Here is my code:
<% # Language="VBScript" %>
<head>
<title>Form to database</title>
</head>
<body>
<%
Dim page: page = Request.ServerVariables("SCRIPT_NAME")
If Request.Form <> "" Then
Dim name: name= Request.Form("name")
Dim email: email = Request.Form("email")
Dim comments: comments = Request.Form("comments")
Dim sql: sql = "INSERT INTO users_tbl " & _
"([name], email, comments) " & _
"VALUES ('" & name & "','" & email & "','" & comments & "')"
Dim conn: Set conn = Server.CreateObject("ADODB.Connection")
Dim str: str = "SERVER=MYSQL-5.idealinsurance.com.au;
DATABASE=ideal_idealinsurance_com_au; UID=XXXXXXXXXX;PASSWORD=XXXXXXXX; OPTION=3"
conn.Open(str)
conn.Execute(sql)
conn.Close
Set conn = Nothing
Dim message: message = "The form information was inserted successfully."
End If
%>
<form action="<%=page%>" method="post">
name:<input name="name"><br>
email:<input name="email"><br>
comments: <textarea name="comments"></textarea><br>
<input name="submit" type="submit" value="Submit">
</form>
<p>
<%=message%>
</body>
</html>