IIS 10和自定义错误页-执行两次

问题描述 投票:0回答:1

为了应对臭名昭著的 "xmlrpc.php "DOS攻击,我为404和500-100两种类型的错误写了自定义错误ASP页面,并使大部分工作正常。 然而,我发现这些页面被执行了两次,原因不明。它们都在发送邮件,也在收集客户的IP,以便自动添加到Peerblock自定义IP块列表文本文件中。 然而,由于双重执行,发送了两(2)封电子邮件,IP地址被添加到Peerblock文本文件中两次。 以下是404页面的代码片段列表。

' Grab the current URL and peform a number of tests (if we can--after the IIS server performs a redirection to a 404 handler, the URL is stripped of all parameters):
TheURL = Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("SCRIPT_NAME")
If Request.ServerVariables("QUERY_STRING") <> "" Then
    TheURL = TheURL & "?" & Request.ServerVariables("QUERY_STRING")
End If

strServer = Request.ServerVariables("SERVER_NAME")
strUrl = Request.QueryString
strPage = Mid(strUrl, InStr(strUrl, strServer) + Len(strServer) + 1)
ClientIPAddress = Request.ServerVariables("LOCAL_ADDR")  
HTTPReferer = Request.ServerVariables("HTTP_REFERER")

If HTTPReferer = "" Then
    If InStr(1, ClientIPAddress, "10.1.252.250", 0) > 0 Then 
        HTTPReferer = "www.edenusa.com"
        WithinSite = True
    Else
        HTTPReferer = "UNKNOWN URL" 
        WithinSite = False
    End If
End If

' Grab the IP address of the client coming into site (used later in email and HTML text):
RemoteIPAddress = Request.ServerVariables("REMOTE_ADDR")

' Don't notify via email when the URL is the following (happens too often):
HTTPRefererStatus = InStr(HTTPReferer, "edenusa.com/") OR InStr(HTTPReferer, "www.edenusa.com/") OR InStr(HTTPReferer, "edenusa.com/favicon.ico") OR InStr(HTTPReferer, "edenusa.com/favicon.gif") OR InStr(HTTPReferer, "edenusa.com/robots.txt") OR InStr(HTTPReferer, "xmlrpc.php")
TheURLStatus = InStr(TheURL, "xmlrpc.php")

If HTTPRefererStatus > 0 Or TheURLStatus > 0 Then

    NoEmail = True ' Do not send an email in this case

    If TheURLStatus > 0 Then ' Write the IP address to our own local Peer Block list:
        ' The format of the file is as follows: #[name]:[IpRangeStart]-[IpRangeEnd]

        Dim objFS
        Dim objFile
        Dim IPBlockFileName: IPBlockFileName = "badiplist-edenusa.txt"

        Set objFS = Server.CreateObject ("Scripting.FileSystemObject")
        sIPBlockListPath = Server.Mappath ("/common/errorhandling/badiplists/" & IPBlockFileName)
        Set objFile = objFS.OpenTextFile (sIPBlockListPath, 8)

        ' Write the IP address out to the IP Block List file:
        objFile.WriteLine "#Test: " & RemoteIPAddress & "-" & RemoteIPAddress

        objFile.Close
        Set objFS = Nothing
        Set objFile = Nothing
    End If
End If


' Using Persits ASPEmail component, send an error report email to the support team.

sAlertBody = "At " & Now() & " a 404 error was encountered when a user attempted to visit the following link: " & HTTPReferer & vbCrLf
sAlertBody = sAlertBody & vbCrLf & vbCrLf
sAlertBody = sAlertBody & "The local IP address is: " & ClientIPAddress
sAlertBody = sAlertBody & vbCrLf & vbCrLf
sAlertBody = sAlertBody & "The remote IP address is: " & RemoteIPAddress
sAlertBody = sAlertBody & vbCrLf & vbCrLf
sAlertBody = sAlertBody & "The value of TheURL is: " & TheURL
sAlertBody = sAlertBody & vbCrLf & vbCrLf

'Send email for evaluation:
'Function IsSuccessfulEmail(sFromAddress, sSenderName, sRecipient, sReplyTo, sSubject, sBody, sCarbonCopyAddress, sFileAttachmentLocation)

If NoEmail = False Then

' Call the emailing function (contained in the /INCLUDEFILES/EMAILOPERATIONS/EMAILFUNCTIONS.ASP file):

    ' Call the AdministrativeAlertEmail() function:
    AlertEmailResult = AdministrativeAlertEmail(sAlertRecipient, sAlertSubject, sAlertBody, sAlertHost)

        If Debug_404ErrorPage = True Then
            Response.Write("LINE-178: This is the value of the AlertEmailResult variable: ") & AlertEmailResult & "<br>"
            Response.End
        End If

Else ' Do not send an email, and reset the variable back to TRUE:

    NoEmail = True

End If
vbscript asp-classic iis-10
1个回答
1
投票

IIS自定义错误页面工具允许通过 "错误页面 "机制定义自定义错误页面。 每个状态码类型(如500),都可以进行编辑,以包含一个相对路径到自己的自定义错误页面。 不幸的是,我发现在500页面中实例化的Server.GetLastError()方法,只返回空值。 网络上的一篇文章描述了一个解决方案,即IIS中的 "编辑功能设置... "可以用来指向一个 "默认页面"。 不幸的是,这导致所有其他定义的自定义错误页被执行两次。 在删除了自定义500错误页面后(如Lankymart所建议),本帖中描述的问题得到了解决。

© www.soinside.com 2019 - 2024. All rights reserved.