asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Redirecting ISAPI Filter
By Wayne Berry
Rating: 3.9 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    This Issue

    In this issue we tackle a common problem of redirecting a lost user with an ISAPI Filter Extension. Here is the scenario, a user visits a site, likes it and adds the site to his/her favorites, later they return to find the page gone. The situation that we want to prevent is the user seeing a "HTTP/1.0 404 Object Not Found." This situation arises with site redesigns where pages are removed, most content providers do this without really thinking of the circumstances. A common solution is too keep the page in place, but make it only a link to the correct URL. Using the 404Redirect this situation can be prevented in a clean simple fashion with out extra pages.

    The Workings

    404Redirect.dll redirects lost users to directories above the one that they are requesting. So for example if a user asks for a page like this:

    http://www.mydomain.com/gooddir/badpage.htm

    Then they would be redirected to

    http://www.mydomain.com/gooddir/

    Where normally, they would have gotten an 404 error.

    Recursion

    Using the example above as a base let's try a harder example. If the user enters a page like this:

    http://www.mydomain.com/goodir/baddir/badpage.htm

    They will be redirected to

    http://www.mydomain.com/goodir/baddir/

    But, this is also a bad request, so when the browser makes this request it gets redirected to:

    http://www.mydomain.com/goodir/

    The filter recursively gets called for every bad request until it reaches the root of the server. All server should have a default page on the root.

    The Code

    Both the code and the compiled filter are both available to download.

    Requirements

    The 404 Redirect can run on any Windows based web server that supports ISAPI Filters. It was design to run on Internet Information Server 1.0 or better.

    To compile the code you will need to have Microsoft Developer Studio 4.2 or better.

    The Code

    Here is both the code and a release version of the DLL. The code is fully commented so that not only do you have the source, but can understand how it works. You will need WinZip to extract the zip file since most of the file names are longer then 8.3.

    Allocating Memory on the Heap

    In both ISAPI Server Extensions and ISAPI Server Filters it is consider bad practice to allocate memory on the heap, since it slows down performance. All memory for strings and alike should be allocated on the stack. This is sometimes limiting since the length of string might not be known. A example of this is demonstrated with lpszURL. lpszURL is a pointer to the start of a string which contains a URL of unknown length. In the 404Redirect code we set the maximum length of lpszURL at 255 and allocate the memory on the stack. We can get away with this because on the circumstances. It is better to limit the ISAPI Extensions for some users then to slow down all the users for the extreme cases.

    Quick String Parsing and Comparing

    Since this type of Filter handles all outgoing data it is important that the majority of the responses are processed quickly. In 404 Redirect the code is only looking for HTTP/1.0 404. The Majority of the responses are non 404 responses, these only have to under go one string compare. Once the responses are separated into 404s and non 404s ( by the one string compare) then we take our time handling the 404 responses. The non 404s exit out of the filter after the string compare to go along their merry way.

    Installing the Filter on the IIS Machine

    Follow the instructions below to add 404Redirect to your server.

    1. Copy 404Redirect.dll to c:\winnt\system32\inetsrv.
    2. Stop the IIS Web Server using the Internet Service Manager.
    3. Select Start | Run from the task bar of NT.
    4. Run regedit.exe
    5. Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters .
    6. Add c:\winnt\system32\inetsrv\404Redirect.dll to the Filter DLLs value. It is important that you add the DLL to the end of this comma delimited list. Do not remove the other entries.
    7. Start the IIS Web Server up using the Internet Service Manager

    15 Seconds

    Thanks for the support. Our last issue (Connection Caching) got read by thousands. Most came to read how to use connection caching with ODBC 3.0. Others where looking for some tricks on how to do user interaction. What ever the reason many came and downloaded the connection caching code.

    This issue (Redirecting Filter), we hope will be more popular, since both developers and system administrators alike can use the code to directly improve their web site. Now that we have the second issue out the door, we will start looking for sponsors.

    Currently, we are running banners at the bottom of the page to advertise ourselves. However, we need to take on sponsors to fund our efforts. Since the readers are mostly developers and system administrators of the Internet Information Server, the viewing audience in narrow. This is a good market for development companies and tool makers.

    The next issue will show how to implement the popular sendmail Unix CGI script using Active Server Pages. Send mail allows you to convert information collected in a form to email, The email is then sent to a specific individual, by the server. The next issue will contain all the source code and a detailed explanation of how the Active Server sendmail works.

    Thanks,
    15 Seconds Editing Staff

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES