When error occurs while you compile or run an ASP page, IIS generates a 500;100 error and executes a Server.Transfer() method to pass control to the currently defined custom error page. (By default this page is "WinDir/help/iishelp/common/500-100.asp")
When control is passed to the custom error page, the Server.GetLastError() method can be used to obtain detailed information regarding the error that occurred. for more info [Creating Custom ASP Error Pages]
While you can setup a custom ASP error page for some website as described in the MSDN article mentioned before; why not customize the default IIS error 500 page [WinDir/help/iishelp/common/500-100.asp] directly,To present users with a friendly error message and do server-wide error logging and/or send it to IT Email..
This is modification for the 500-100.asp to display an error message and send email to IT:<%@ language="VBScript" %>
<% Option Explicit
If Response.Buffer Then
Response.Clear
Response.Status = "500 Internal Server Error"
Response.ContentType = "text/html"
Response.Expires = 0
End If
Call SendError()
%>
<html>
<head>
<style>
Body,TD {FONT-SIZE: 11px; FONT-FAMILY: Tahoma }
</style>
<META NAME="ROBOTS" CONTENT="NOINDEX">
<title>Unexpected Error</title>
<META HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">
</head>
<body>
<h3 align="center">Unexpectd Error</h3>
An unexpected error has occurred. We apologize for the inconvenience.
<p>Please try the following:</p>
<ul>
<li>Click the <a href="javascript:location.reload()">Refresh</a> button, or try again later.</li>
<li>Open the home page, and then look for links to the information you want. </li>
</ul>
</body>
</html>
<%
Sub SendError()
Dim er : Set er = Server.GetLastError
Dim msg : msg = "Error 500 on "& Now &"<br>"
msg = msg & "category:"& er.Category & "<br>"
If er.ASPCode>"" Then msg = msg & "aspcode:"& er.ASPCode & "<br>"
msg = msg & "number:"& hex(er.Number) & "<br>"
If er.ASPDescription > "" Then
msg = msg & "description:"& er.ASPDescription & "<br>"
ElseIf er.Description >"" Then
msg = msg & "description:"& er.Description & "<br>"
end If
If er.Source > "" Then msg = msg & "source:"& er.Source & "<br>"
If er.File <> "?" Then
msg = msg & "file:"& er.File & "<br>"
If er.Line > 0 Then msg = msg & "line:"& er.Line & "<br>"
If er.Column > 0 Then msg = msg & "column:"& er.Column & "<br>"
End If
msg = msg & "USER_AGENT:"& Request.ServerVariables("HTTP_USER_AGENT") & "<br>"
msg = msg & "REQUEST_METHOD:"& Request.ServerVariables("REQUEST_METHOD") & "<br>"
msg = msg & "SCRIPT_NAME:"& Request.ServerVariables("SCRIPT_NAME") & "<br>"
if Request.QueryString>""Then msg = msg & "QueryString:"& Request.QueryString & "<br>"
if Request.Form>""Then msg = msg & "Post:"& Left(Request.Form,500) & "<br>"
Call SendEmail(IT_Email,IT_Email,"Error 500",msg)
End Sub
%>
* don't forget to disable "Show friendly HTTP error messages" In IE under Tools/Internet Options/Advanced
0 comments
Post a Comment