Monday, September 7, 2009

How to Configure Error 404 Page in ASP for IIS Server?

Error 404 PageLet us assume you have created an .asp file called error404page.asp, which is customized to handle HTTP 404 errors. When a visitor to your site tries to access a page that does not exist on your server, say a page called missedpage.asp, then the ASP file will be invoked as if the user had typed:
‘;’ in the Web browser.

From the information with the above query string, "404;", we can show the user the page they have requested, and send instant information to the administrator. Let us see how this can be done.

Save the file error404page.asp in the root folder of your web site which you have created to handle the HTTP 404 errors. As mentioned in my previous post ‘How to configure Error 404 page in IIS Server’ configure the custom 404 message of your web site to point to the URL, error404page.asp.

To track the URL that triggered the HTTP 404 Error, we have to write a code in the asp page error404page.asp with the help of Request.query string. Then we have to clean the captured query string to get the requested URL and send a mail to the site administrator using CDONTS. We will then display the page to the user after completing all the server side processing.

In the ASP page, error404page.asp, copy the following code to display to the user when a HTTP 404 error occurs:

<%@Language="VBScript" %>
'error404page.asp - ASP file for handling Customer Error
'Messages mapped to a URL
Dim capturedQryStrg
Dim requestedURL
'As I explained above, the entire query string starts with
'the error number, followed by the requested URL
capturedQryStrg = Request.ServerVariables("Query_String")
'Once we have captured the entire query string, in this
'case "404;", let us
'clean it by removing the "404;", leaving us with just the
'requested URL
requestedURL = Replace(capturedQryStrg, "404;", "")
'After we are done with cleaning up, we will send a mail
'to the site administrator using the CDONTS object.
'We will mark the email as urgent.
Dim errMail
Set errMail = Server.CreateObject("CDONTS.NewMail")
errMail.From = ""
errMail.To = ""
errMail.Subject = "URGENT - 404 Error"
errMail.Body = "User requested - " & requestedURL
errMail.Importance = 2
Set errMail = Nothing
'We are done with the server-side processing.
'We will now display the content to the user.
<Title>Sorry, but <% = requestedURL %> was not found on</Title >
The page you requested, <%= requestedURL %>was not found on<br>
It's possible you typed the address incorrectly, or that the page no
longer exists. <br>
An email alert has been sent to the administrator regarding this error.<BR>
As an option, you may visit any of the pages below for information about our services or products:<BR>
Contact Us

If you find this post more useful then, Please

Subscribe to this Blog:

Click here to Subscribe to FREE email updates from "Internet Marketing Insights"

Stumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditAdd To FacebookAdd To Yahoo

People who read this post also read :



Creative Commons License

Blog directory Internet Marketing Insights - Blogged Internet Blogs - Blog Catalog Blog Directory