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

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

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

Firing Events in a Shared Hosting Environment
By Matthew Muller
Rating: 3 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction


    Firing events on a Web server is an easy task. Depending upon what type of solution you are trying to provide and what type of event you are trying to fire on a predetermined basis, you could use the Win2K Scheduled Tasks, SQL Server Agent or the "at" command. However, all of these tools require you to have your own dedicated Internet Information Server (IIS) or SQL Server on the Internet to play with, a privilege not shared by many. Since most (all that I could find) Microsoft-based Internet Service Providers (ISPs) do not allow you access to these tools, you need to get a little creative in order to get the same functionality as you would if you did have your own dedicated server.

    Body

    The first step in firing your event is to create an ASP that does whatever you need it to do. In my case I needed it to pull a number of values from a database, including an email address, and then send out dynamically generated emails based on the user values. You can think of it as a script that allows you to do target marketing.

    Once your ASP is built and uploaded to your ISP, you should be able to call it from a Web browser and make sure it performs properly. The next step is to create the functionality that makes the ASP fire at a specific time (or times) every day, month, weekday, etc. The two key pieces of technology used to accomplish this on a Unix box are called "cron" and "lynx." The text-based Internet browser "lynx" can be run from a Unix command line, and "cron" is a clock daemon that permits the firing of events repetitively at predetermined times.

    Using Cron

    To use the "cron" clock daemon, you need to create crontab files. I am by no means a Unix programmer, but managed to get the functionality working without too much of a hassle. If you do a search on "cron" and "crontab" on a search engine, you should find numerous examples of how to use this technology. I've listed the sites that I used at the bottom of this article. The basic format of a cron entry is:

    minute hour day month year command

    My cron file looked like this:

    
    00 3 * * 1-5 lynx -dump -cookies -auth=mylogin:mypassword
    http://myservername.com/email/sendemail.asp
    
    
    The above cron file calls the lynx command (with some parameters which I'll cover later) at 3 a.m. every weekday.

    Using Lynx

    For this text-based Internet browser that can be run from a Unix command prompt, the command I call from cron is

    
    "lynx -dump
    -cookies -auth=mylogin:mypassword
    http://myservername.com/admin/sendemail.asp".
    
    
    It calls that ASP that I created previously. The lynx command requires a number of parameters (see the following list). Some of these are important if you want your script to run unattended.

    -cookies
    My site uses cookies, so the -cookies parameter makes lynx auto-accept cookies.

    -dump
    This parameter simply dumps whatever would have been displayed on the screen out to the command line and then exits from lynx.

    -auth=mylogin:mypassword
    This parameter is required if you are accessing a URL that requires a login and password. I placed my sendemail.asp file in a secure directory (email) so that it is not run by anyone stumbling across the URL.

    Finding an ISP

    For all of this to fit together and work, you need an ISP that has both a Unix server and Microsoft server. Your ASP runs on IIS and your cron command runs on the Unix box. Most Microsoft based ISPs that run NT or Win2K also give you a mail server to play with that usually runs on Unix, so you shouldn't have too much problem finding an ISP to support you. Simply telnet into your mail server and run the "crontab -l" command, and you'll quickly find out whether your ISP has blocked access to the command or not.

    Summary

    There are a number of ways that you can use the idea presented in this Article. Targeted emails are only one of many. I have not included any of my ASP code that actually reads from the database and sends out the email because this topic is covered numerous times in other articles. This article focuses more on how to fire events from a shared server environment.

    Helpful Links

    For information on crontab, cron, and lynx, see the following:

    http://campuscgi.princeton.edu/man?crontab
    http://campuscgi.princeton.edu/man?cron
    http://campuscgi.princeton.edu/man?lynx

    Information on the "at" command can be found at http://campuscgi.princeton.edu/man?at.

    About the Author

    Matthew Muller is a senior consultant with Cap Gemini Ernst & Young's Microsoft Advanced Development Center in Bellevue, Washington. An Australian native, Matt has lived in the United States since 1997 after studying as an exchange student at Purdue University. He has been developing Internet applications using Microsoft-based technologies for large companies since 1998. He is also involved in the development of a number of nonprofit Web sites, including usfooty.com, a Web site that serves as the central point for Australian Rules Football in the United States. He can be reached at matt@seattlefooty.com.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    CustomError 2.0 for IIS
    When errors occur on a Web site, they should be handled in a way that helps the user to get back on track. Unfortunately, setting up customized error pages in IIS usually requires something many Web developers lack -- access to and familiarity with the Web server's administrative interface. With CustomError for IIS, developers can add error pages, coded by hand or created in their favorite editor, by simply uploading them to a designated directory. No administrator intervention is required.
    [Top]
    Other Articles
    Aug 7, 2002 - Using MySQL in the Win32 Environment
    Developers who don't want to spend a lot of money on SQL Server and who want a database that's more robust than Access may find MySQL to be a pleasant alternative. This introductory article covers the bare essentials for getting MySQL installed and running in the Win32 environment.
    [Read This Article]  [Top]
    Jul 17, 2002 - Software Development: Steps To Better Ensure Success
    There is never a guarantee of project success when endeavoring to build a sophisticated application. However, there are established steps to follow that will ensure a clear, concise scope, support for the team involved, and a solid opportunity for successful deployment.
    [Read This Article]  [Top]
    Jul 15, 2002 - Securing SQL Server for Web Applications
    If your SQL Server is exposed to the Internet, then hackers are probing it. This article shows how to secure a SQL Server database that's being used with a Web application
    [Read This Article]  [Top]
    Jul 1, 2002 - Protecting Your Web Application Against Dangerous Requests
    Enrico Di Cesare provides a solution for hiding and securing querystring values that pass through a url.
    [Read This Article]  [Top]
    Apr 2, 2002 - Object-Oriented Programming for VBScripters
    Feel intimidated by .NET? This article by Rob Chartier is designed to ease any level VBScripter (ASP) into .NET by clarifying some OOP concepts.
    [Read This Article]  [Top]
    Mar 27, 2002 - A Best Practice for Using ADO Objects
    A few members of the 15 Seconds discussion list talk about the proper way to use methods in order to prevent ADO object errors.
    [Read This Article]  [Top]
    Jan 2, 2002 - The ASP.NET Page Life Cycle
    Solomon Shaffer explores the life cycle of an ASP.NET page from initialization to unloading. He also explains the various methods to override ASP.NET server-side events.
    [Read This Article]  [Top]
    Dec 19, 2001 - Application Architecture: An N-Tier Approach - Part 2
    Rob Chartier creates a simple portable and reusable address book in .NET to demonstrate the power of N-tier application architecture. Complete source code included!
    [Read This Article]  [Top]
    Oct 23, 2001 - Application Architecture: An N-Tier Approach - Part 1
    Learn about N-tier application architecture and realize that developing with multiple layers produces a flexible and reusable application for distribution to any number of client interfaces.
    [Read This Article]  [Top]
    Oct 23, 2001 - Application Architecture: An N-Tier Approach - Part 1
    Learn about N-tier application architecture and realize that developing with multiple layers produces a flexible and reusable application for distribution to any number of client interfaces.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry