IIS,ASP,will,explain,step,customize,your,File
Quick Search for:  in language:    
IIS,ASP,will,explain,step,customize,your,File
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 144,429 lines
 Jobs: 168 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Click here to see a screenshot of this code!Ping in ASP
By Michele_Garneri on 10/28

(Screen Shot)

Embed Real Player Object
By Ziae Mousavi m. on 10/27


Set Country --> Combobox
By Hohl David on 10/27


Client Side Sorting of records
By Ravi Rajan on 10/26


Recordset paging with images
By Ravi Rajan on 10/26


Click here to see a screenshot of this code!Online photo catalogue VBScript 2.1
By Ivan Loire on 10/26

(Screen Shot)

GPS 1.4 WYSIWYG
By Guo Xu on 10/25


Click here to see a screenshot of this code!A Network Monitor tool from ActivXperts Software Inc.
By Freddy Hofstadt on 10/25

(Screen Shot)

Socket samples based on Winsock, TCP/IP and client/server communication
By Ronny Bright on 10/25


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Tracking 404 Errors

Print
Email
 

Submitted on: 7/31/2000 11:11:25 AM
By: Nathan Pond  
Level: Beginner
User Rating: Unrated
Compatibility:ASP (Active Server Pages)

Users have accessed this article 6331 times.
 
(About the author)
 
     This will explain (step by step) how to customize your 404 File Not Found page in IIS 4.0. It will also tell you how to use ASP to log this information so that it may be corrected, you could log it to a database, send an email to the webmaster, or just about anything you want to send out an alert.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
Tracking 404 Errors
By Nathan Pond


"404 - File Not Found" We've all seen this hundreds of times. As hard as we all try to spare our users from seeing such a thing, the simple fact is there is no way to prevent this from happening. However, configuring IIS 4.0 and using some simple ASP can display a custom, formatted page to the user while at the same time logging the incorrect URL to a database or sending the webmaster an e-mail. You can not afford to wait for your users to report incorrect links on your site, you want to be notified when the error happens. In this article I'll explain how you can do that.

Keep in mind that you don't have to log errors, you may simply just want to use your own 404 page instead of the default one that shows on the users browser. In either case, the first step is to create the custom 404 page that you want to show to the user. You can be as creative as you want with this, some web sites have very humorous 404 pages. You can visit http://www.npond.com/404.shtml to see what I did with mine, maybe give you some ideas.

When creating the page, you will probably want to name it /404.asp for easy recognition. If you do not want to track the error to a database or e-mail, you could make it a plain html file instead of ASP.

You have your page created, at least the html part of it. We'll get the ASP in a little bit. The next step is to configure IIS to send your 404 file whenever it can't find the file specified by the users browser. To do this open Microsoft Management Console (MMC). You may make the 404 page you have work for your entire server, only specified webs, or even specified directories within a web. For now we will configure one web on your web server to use this 404 page. Right click on the name of the web you wish to configure, and click on Properties. A dialog window opens with many different tabs, you want to click on the Custom Errors tab. Here you have a list of every server error IIS has a page for. You can customize anyone of them, but for now scroll down the list and select 404, and click on the Edit Properties button.

Now a dialog window pops up and gives you the option to select the Message Type; if you are simply displaying a formatted page and aren't using an ASP file, you can select File from this list. If you are using an ASP page you should select URL. If you selected File as the message type, you should then click the Browse button under the text box to select the file to use. If you selected URL you must type the virtual path (/404.asp) on your server to the script that will be executed.

Click the Ok button to close this dialog, then click Ok to save the web properties. At this point, your web will now show your 404 page instead of the default 404 page. Now it's time to put some ASP code into it!

When a 404 error is triggered, IIS will direct the user to your custom ASP script and pass the incorrect URL in the querystring. All we need to do is parse it. We can also use Server Variable HTTP_REFERER to find out if this page was linked to, and where it was linked from. Put the following ASP code near the top of your /404.asp page:

    <%
    Dim strURL, strReferer
    strURL = Request.ServerVariables("HTTP_URL")
    strURL = Right(strURL, (Len(strURL) - (Instr(strURL, chr(59)))))
    strReferer = Request.ServerVariables("http_referer")
    %>
    

This code will assign the strURL variable with the incorrect URL that the user tried to access. It will also put the refering page into the strReferer variable. Now it is a simple matter of sending an e-mail using CDONTS (or some other component) and/or loggin this information to a database. Note that if strReferer is empty or null then the page was not accessed via a link, the user typed in the address. If strReferer has a value it is the value of the URL that linked to the non-existent file on our server.

For information on using CDONTS to send e-mail from ASP, please see: Sending Emails in ASP using CDONTS.


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/21/2000 7:57:54 AM:Luis Ferro
I just want to notice that if the users have
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/28/2001 5:22:02 PM:Dedw8
I know little about asp programming, but to me it looks like you DIM statement does not correctly declare your variables. Small, but the statement should read: Dim strURL, strReferer. Am I out to lunch?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.