Is it possible to capture all 500 errors in Classic ASP at a global level? Maybe something in IIS. I'm using II6 at the moment. I like to capture the error message and then store it in the database. I know its possible in ASPX pages, but don't know exactly how you do in classic asp.
Thank you
Yes, create an asp page which will log the error details to the database, and set this to be the 500 handler page in IIS as below.
Use the Server.GetLastError object to get the details of the error in your handler script.
It might be a good idea to log to a text file rather than a DB in your 500 handler for resiliency.
Complementing Jon's answer, use this script to write errors to a log file:
<%
'Set this page up in IIS to receive HTTP 500 errors
''Type' needs to be 'URL' and the URL is e.g.: '/500Error.asp' if this file is named '500Error.asp' and is in the site root directory.
'This script assumes there is a "/Log" folder, and that IIS has write access to it.
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim objFSO, err
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set err = Server.GetLastError()
outFile=Server.MapPath("/Log/ErrorLog.txt")
Set objFile = objFSO.OpenTextFile(outFile, ForAppending, True, TristateTrue)
objFile.WriteLine Now & " - ERROR - ASPCode:" & err.ASPCode & " ASPDescription: " & err.ASPDescription & " Category: " & err.Category & " Description: " & err.Description & " File: " & err.File & " Line: " & err.Line & " Source: " & err.Source & vbCrLf
objFile.Close
Set objFile = Nothing
Set err = Nothing
%>
Error handling in classic ASP is a complete pain. You can catch the error where you think it's going to occur using on error resume next, then check for the error code in the following line of code.
Alternately you can scan the server logs for 500 errors. or set up a "500 error" page in your IIS settings.
On Error Resume Next
... do something...
If Err.Number <> 0 Then
... handle error
end if
To add to #Jon Eastwood's answer - if you are using IIS 7.5, then instead of "Custom errors" you will look for ".NET Error Pages" per the image below:
This applies to Windows Server 2008 and other newer Windows SKUs.
Related
I have some ASP.NET code that I need to send an email this is the procedure I have cribbed on how to do that and it tries to send the email but after a fairly long pause comes up with this full error message:
"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated."
I have poured over a lot of similar errors on this site and applied some of the fixes that should allow my code to send email and none work.
My ASP.NET code is running on a 2012 r2 Server that is on the same internal network as the mail server which is running Server 2008 r2 and Exchange Server 2013.
The ASP.NET server can be accessed via "remote.domainname.co.uk" and the Mail Server can be accessed via "mail.dommainname.co.uk" where domainname is a placeholder for the actual domain name.
This is the code that I am using:
Dim mailto As New MailAddress("toaddress#mydomain.com") 'My developer email add for testing.
Dim mailfrom As New MailAddress("fromaddress#domainname.co.uk")
Dim message As New MailMessage(mailfrom, mailto), Msg As String = ""
Dim mailClient As New SmtpClient()
Dim UserAndPass As New NetworkCredential()
Dim Script = ""
Dim n As Integer = 0
Dim BodyText As String = ""
Try
message.Subject = "Issue relating to " & p.IssueDescription & "."
'Create the body text:
BodyText = "This email is to bring to your attention the following issue:" & NNL
BodyText += "Building: " & p.Building & NL
BodyText += "Location: " & p.Location & NL
BodyText += "Issue:" & p.IssueDescription & NL
BodyText += "Additional Information:" & NNL
BodyText += p.AdditionalInfo & NNL
BodyText += "Sent from the XYZ Logging System." & NL
BodyText += "Date: " & Now.ToShortDateString & NL
BodyText += "Time: " & Now.ToShortTimeString
message.Body = BodyText
'send the message
mailClient = New SmtpClient("mail.domainname.co.uk", 25)
mailClient.EnableSsl = True
mailClient.UseDefaultCredentials = False
mailClient.Credentials = New Net.NetworkCredential("fromaddress#domainname.co.uk", "passwordtext")
mailClient.Send(message)
Script = "alert('"
Script += "The Patrols Issue Email has been successfully sent!"
Script += "')};"
ClientScript.RegisterStartupScript(Me.[GetType](), "alert", Script, True)
Catch ex As Exception
PEH("SendEmail", "frmName", ex.Message) 'My error handler
Finally
'f.Dispose()
mailClient.Dispose()
message.Dispose()
End Try
On the Exchange server I have the standard set of receive connectors and I have checked that they are all configured as per the standard install and they are. I did try creating my own receive connector but this caused problems with emails being sent from remote senders getting bounced with the same "Client was not authenticated" error so I removed it again.
Any help with this would be appreciated.
Graham Sivill.
We are upgrading our servers and .net application from windows 2000 to the newly-purchased windows 2012R2 servers. There is one function which works in windows 2000 but doesn’t work in windows 2012R2.
We are running an .net 2.0 internal application in windows 2000 and IIS 5.0 using Visual Studio professional 2015. There is one function in this application which will make a function call to an AD server using LDAP to check the login id and password in Active Directory. It is running perfectly fine before. However, once I upgrade to this new window2012R2 server running .net 2.0, it doesn’t work. The function in the application is not able to get authorization in the Active Directory. The function as below:
Private Function IsAuthenticatedByAD(ByVal sUid As String, ByVal sPwd As String) As Boolean
Dim direntRoot As DirectoryEntry, direntUsr As DirectoryEntry
Dim sDomain As String, sDomainAndUid As String
Dim dirsrchUsr As DirectorySearcher, oNative As Object
direntRoot = New DirectoryEntry("LDAP://rootDSE")
sDomain = direntRoot.Properties("DefaultNamingContext")(0)
sDomainAndUid = String.Format("{0}\{1}", sDomain, sUid)
direntUsr = New DirectoryEntry(direntRoot.Path, sDomainAndUid, sPwd)
Try
oNative = direntUsr.NativeObject
Catch ex As Exception
Return False
End Try
Return True
End Function
I received error message in the "Try" section when run oNative = ....
The error message as below:
"System.DirectoryServices.DirectoryServicesCOMException (0x8007052E):
The user name or password is incorrect." & vbCrLf & vbCrLf & " at
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)" &
vbCrLf & " at System.DirectoryServices.DirectoryEntry.Bind()" &
vbCrLf & " at
System.DirectoryServices.DirectoryEntry.get_NativeObject()" & vbCrLf &
" at ums.business.UsrMgmtBus.IsAuthenticatedByAD(String sUid, String
sPwd) in C:\inetpub\wwwroot\ums\business\UsrMgmtBus.vb:line 127"
Please help. Thanks a lot.
I get an error at the following line in my application:
'create NewMail object'
Line 96: Function SendHTMLEMail (strFrom, strTo, strCC, strSubject, strBodyHTML)
Line 97: Set objNewMail = Server.CreateObject("CDONTS.NewMail")
The error is:
Error Type:
Server object, ASP 0177 (0x800401F3)
Invalid class string
/Utils.inc, line 97
I have added interop.CDONTS.dll to the references of application, but still I am getting same error.
I am not sure if this functionality is used in any other page and is working.
I use .NET 2003 framework 1.1, and the server is running Windows Server 2003
ASP-Classic
Since CDONTS is discontinued since Win2000 and newer you should switch to CDOSYS.
Sample code for sending via remote server
Set oMessage = CreateObject("CDO.Message")
Set oConfig = CreateObject("CDO.Configuration")
Set oFields = oConfig.Fields
With oFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.acme.com"
.Update
End With
With oMessage
Set .Configuration = oConfig
.To = "recipient#acme.com"
.From = "sender#acme.com"
.Subject = "A Subject Line"
.TextBody = "A Text body message"
.Fields.Update
.Send
End With
The linked site features detailed examples for all kinds of scenarios.
ASP.NET
If you are targeting ASP.NET you should use System.Net.Mail instead of CDO
I got the solution. I added a new CDONTS.dll and registered it using
regsvr32 C:\SYSROOT\system32\cdonts.dll
This solved the problem. No need of adding it to the references.
How can I call to a ASP.NET file (.aspx) from a VBS file that are both on the SAME server ?
I need that the VBS file will execute the asp.net file with some parameters.
Thanks
something like this?
Dim ie
Set ie = CreateObject("internetexplorer.app location")
ie.Navigate "http://www.mysite.com/mypage.aspx?q=1"
ie.Visible=True
or
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "iexplore http://www.mysite.com/mypage.aspx?q=1", 9
WScript.Sleep 10000 ' Give ie some time to load
'Close the browser
WshShell.SendKeys "%F"
WshShell.SendKeys "C"
or
rebember that you run web pages directly from the Task Scheduler and use curl
You can use ServerXMLHttp:-
dim xhr : set xhr = CreateObject("MSXML2.ServerXMLHttp.3.0")
xhr.open "GET", "http://yoursite/youcode.ashx?params=x", false
xhr.send
if xht.status = 200 then
msgbox "Success :)"
else
msgbox "Failed :("
You can use the following in your .vbs file
Set winHttpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
winHttpRequest.Open "GET", "http://localhost/mypage.aspx", false
winHttpRequest.Send
WScript.Echo(winHttpRequest.GetAllResponseHeaders())
WScript.Echo(winHttpRequest.ResponseText)
For more examples, see http://www.neilstuff.com/winhttp/
You should be able to call any URL (including .aspx pages) on your server (or on the internet)
I'm using Microsoft.XMLHTTP to get some information from another server from an old ASP/VBScript site. But that other server is restarted fairly often, so I want to check that it's up and running before trying to pull information from it (or avoid my page from giving an HTTP 500 by detecting the problem some other way).
How can I do this with ASP?
You could try making a ping to the server and check the response.
Take a look at this article.
All you need to do is have the code continue on error, then post to the other server and read the status from the post. Something like this:
PostURL = homelink & "CustID.aspx?SearchFlag=PO"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.3.0")
on error resume next
xmlhttp.open "POST", PostURL, false
xmlhttp.send ""
status = xmlhttp.status
if err.number <> 0 or status <> 200 then
if status = 404 then
Response.Write "ERROR: Page does not exist (404).<BR><BR>"
elseif status >= 401 and status < 402 then
Response.Write "ERROR: Access denied (401).<BR><BR>"
elseif status >= 500 and status <= 600 then
Response.Write "ERROR: 500 Internal Server Error on remote site.<BR><BR>"
else
Response.write "ERROR: Server is down or does not exist.<BR><BR>"
end if
else
'Response.Write "Server is up and URL is available.<BR><BR>"
getcustomXML = xmlhttp.responseText
end if
set xmlhttp = nothing