|
|
In the previous chapter, we looked at how to create and configure basic websites on IIS 6. But IIS is more than just a web hosting platform, it’s an application server that supports a variety of application architectures, including ASP, ASP.NET, ISAPI, and legacy CGI. We’ll begin this chapter by examining these different types of dynamic applications and then look at how to create and configure applications to run on IIS.
IIS 6 supports a variety of application architectures to provide both flexibility in application development and compatibility with earlier IIS platforms and non-Microsoft web server platforms. The four main types of applications that can run on IIS 6 are ASP, ASP.NET, ISAPI, and CGI.
ASP stands for Active Server Pages and was developed by Microsoft for version 3 of IIS, which was part of the Windows NT 4 Server platform. ASP is a server-side scripting environment that can be used to create dynamic and interactive web applications. ASP pages usually have the file extension .asp and are generally written using Visual Basic Scripting Edition (VBScript) or JScript, two scripting languages developed by Microsoft specifically for the ASP environment (VBScript is an offshoot of Visual Basic [VB], while JScript is Microsoft’s equivalent of Netscape’s JavaScript language). However, the ASP model can be extended to use scripts written in other languages such as Perl, which is commonly used on UNIX platform web servers like Apache.
The way ASP works is that a client (web browser) begins by requesting an .asp page from a website or virtual directory on IIS. When the server receives the HTTP request, it passes the request to the ASP script interpreter, an ISAPI extension called asp.dll. This interpreter then processes the script and generates an HTML response for the client and/or performs some other action such as calling a COM component in order to write a record to a database.
ASP was originally developed by Microsoft as an alternative to the slower CGI script-processing architecture common on UNIX platforms and the more complex ISAPI model Microsoft developed for IIS 2 (more about these two architectures in a moment).
Writing ASP applications is easy if you have basic knowledge of HTML and previous experience with either VB or JavaScript. Here’s a simple ASP application that displays the date and time when the client runs the application:
<HTML> <BODY> <H1>Welcome to ASP!</H1> <P>This page was last refreshed on <%= Now() %><P> </BODY> </HTML>
Note that the executed script is contained between the delimiters <% and %> and is embedded within a standard HTML page. No scripting language has been explicitly declared for this ASP page, so ASP assumes the default scripting language (VBScript) has been used.
To run the preceding application, create it using Notepad, save it as the filename Default.asp, and copy it to the home directory of the Default Web Site on your IIS machine (you’ll do this later in this chapter).
ASP has been steadily improved since version 3 of IIS, with new features being added to speed up and simplify the development process and make ASP applications more powerful. Some of these new features of ASP in IIS 6 include
Greater reliability by detecting hung ASP threads and fixing them by recycling the worker process that hosts the instance of asp.dll associated with the thread.
Improved error handling that lets you trap errors and display them in custom error message .asp files.
Improved performance by automatically spawning additional threads when required, including a self-tuning feature that automatically reduces the number of threads should the server become processor-bound.
Improved performance for scriptless .asp pages that contain only HTML and no script content (in earlier versions you had to name these pages as .htm for best performance).
Better security through encoding ASP scripts so that they appear on both server and client side as unreadable ASCII characters.
There are also a few changes to ASP in IIS 6 that you need to watch out for if you are developing ASP applications for that platform:
ASP is disabled by default on IIS 6 and must first be enabled before your applications will run.
ASP will not support parent paths unless the metabase is configured to allow it to do so (this prevents various kinds of hacking attacks).
There are some changes in how the global.asa file handles the security context for the execution of events.
For more information about these changes, see the ASP documentation for IIS.
ASP is a popular platform for developing web applications for IIS, and it’s been around for a few years now, so there are lots of good sites where you can learn how to use it. Here are a few of my favorites:
www.learnasp.com
www.asp101.com
www.15seconds.com
www.aspin.com
www.asp-help.com
Most of these sites are now emphasizing the new ASP.NET platform that is included with IIS 6, and you may need to drill down to find “classic ASP” material on them. Of course, IIS 6 still supports ASP for backward compatibility and more easily migrating legacy ASP applications to the new platform; but for new applications, you might consider developing them using ASP.NET, which I’ll discuss next.
ASP.NET is a brand new programming model from Microsoft for developing dynamic web applications for IIS 6. ASP.NET is more than just a new version of ASP. It incorporates important features of Microsoft’s new .NET Framework, such as the common language runtime (CLR), which allows ASP.NET applications to make use of inheritance, type safety, versioning, and language interoperability, and enabling ASP.NET applications to be more robust, scalable, and reliable than legacy ASP applications. ASP.NET also supports the latest web standards such as Extensible Markup Language (XML) and Simple Object Access Protocol (SOAP), which makes ASP.NET an ideal platform for developing enterprise-class web services.
ASP.NET supports many more programming languages than ASP (more than 25 at time of writing), making it a much more flexible development environment. Among the languages ASP.NET natively supports are VB.NET, JScript.NET, and C#. ASP.NET recognizes most ASP code, too, which makes it relatively easy to migrate legacy ASP applications to the ASP.NET platform. ASP also supports COM+, the latest version of Microsoft’s architecture for developing distributed applications.
In addition to these improvements, ASP.NET simplifies the process of building applications by providing server controls for displaying data, validating, user input, and other common tasks. These controls generate HTML code that works with any web browser and enable ASP.NET applications to be written faster and with less code than legacy ASP applications. Using Visual Studio.NET, you can rapidly build and deploy ASP.NET applications with the same ease with which you can create VB applications. For example, you can visually design a Web Form by dragging and dropping controls onto the page and double-clicking them to configure their parameters. This is indeed cool.
Other advantages of ASP.NET over ASP include:
Easier deployment Simply copy your ASP.NET files to your web server. You don’t even need to restart the server to get your application up and running.
Better performance ASP.NET runs as compiled code, it’s not interpreted like ASP. This can significantly improve the performance of your web applications.
Flexible caching ASP.NET can cache entire pages or portions of pages as needed to increase application responsiveness.
Better internationalization ASP.NET uses Unicode (UTF-8) internally for representing request/response data.
Easier debugging ASP.NET includes a tracking feature that makes it easier to debug faulty applications.
Easier configurability ASP.NET configuration settings are stored in text files and formatted in XML for easy editing.
Web farm session state ASP.NET lets multiple IIS servers in a web farm share session state information for a single application, making IIS more scalable.
Improved crash protection ASP.NET automatically detects memory leaks and deadlocks and tries to recover from them with no intervention needed.
Support for .NET Framework This support includes .NET class library, Web Forms, and XML Web Services.
Creating a simple ASP.NET application is just as easy as writing one with ASP. Here’s a simple ASP.NET application that displays the date and time when the client runs the application:
<HTML> <BODY> <H1>Welcome to ASP.NET!</H1> <P> This page was last refreshed on <% Response.Write(DateTime.Now.ToString()) %><P> </BODY> </HTML>
Again, the VBScript code that is executed is contained between the delimiters <% and %> and is embedded within a standard HTML page. To run the preceding application, create it using Notepad, save it with the filename Default.aspx (note the new .aspx extension for ASP.NET pages), and copy it to the home directory of the Default Web Site on your IIS machine. Of course, ASP.NET first has to be installed and enabled! I’ll walk you through this process later in the chapter in the section entitled “Working with ASP.NET.”
Note | The files within an ASP.NET application can have a variety of extensions including .htm for plain HTML files, .aspx for Web Forms pages, .ascx for Web Forms user controls, .asmx for XML Web Services, .config for application configuration files, .dll for compiled assemblies saved as project DLLs using Visual Studio.NET, and so on. DLLs for ASP.NET applications generally go in the \bin subdirectory of your website’s home directory, while other files can be located in local or remote virtual directories. |
Of course, there’s a lot more to ASP.NET than this simple example illustrates. I could talk next about using the global.asax file for adding event handling logic to your application, or discuss how to manage application state using various methods, or explain the purpose of the machine.config and web.config files. But this is not a book on how to develop ASP.NET applications—our focus is on how to configure them to run on IIS 6.
Note | You can run ASP and ASP.NET applications side by side on the same IIS 6 server. This gives you the flexibility to support older apps written for earlier versions of IIS while migrating them to ASP.NET and testing them. |
Internet Server Application Programming Interface (ISAPI) was created by Microsoft as a replacement for the CGI processing model popular on UNIX web server platforms. ISAPI really represents two kinds of routines:
ISAPI applications These can be called from any web page to perform dynamic and interactive functions like accessing a database or validating a form. Another name for these is ISAPI extensions, because ISAPI can extend the functionality of IIS beyond serving static HTML and do things similar to what ASP applications do (only faster). ISAPI applications can be written in several different languages but are usually written in C++ for best execution performance. ISAPI applications can be configured at either the web site or virtual directory level, so a single web site may have multiple ISAPI applications running in different directories performing different application-related tasks when they are called.
ISAPI filters These are used to preprocess and post-process HTTP requests and perform actions such as compressing or encrypting information, performing redirection, monitoring security, and so on. ISAPI filters are always written in C++, as they usually examine all incoming traffic for your site and so have to be built for speed. ISAPI filters are always configured at the web site level—you can’t configure an ISAPI filter for a virtual directory within a site.
The main advantage of ISAPI over CGI is that it avoids the performance penalty incurred by CGI, which spawns a new process each time code is run. However, the problem with the ISAPI model is that you need C++ or similar high-level programming knowledge to develop ISAPI applications and filters, while CGI apps are commonly written using Perl or some other interpreted scripting language. Because of the development cost of writing C++ code, Microsoft developed the simpler ASP model described earlier that is more widely used than ISAPI.
We’ll look briefly at several aspects of configuring ISAPI extensions and installing ISAPI filters on IIS later in this chapter in the section entitled “Working with ISAPI.”
Note | Because IIS 6 supports wildcard script mappings, which are discussed in the section “Working with ISAPI,” you can now use ISAPI extensions anywhere ISAPI filters were used in previous versions of IIS. ISAPI extensions can be executed asynchronously (while ISAPI filters can only be executed synchronously), so Microsoft recommends that ISAPI filters no longer be used with IIS 6 and that you replace them with suitable ISAPI extensions wherever possible. |
The Common Gateway Interface (CGI) is a programming model originally developed for web servers running on the UNIX platform. CGI programs are typically either scripts written in Perl, Python, or some other scripting language, or executables written in C or C++. On UNIX web servers, these programs are usually placed in the \cgi-bin directory on your web server and called from web pages for performing tasks such as processing input from forms or writing a record to a database. IIS supports CGI mainly to simplify the process of migrating applications from UNIX to IIS; for most purposes today, ASP is used for developing applications for IIS.
We’ll look briefly at how to install and configure CGI applications on IIS later in the section “Working with CGI.”
Note | The term Web Server Extension refers to any feature of IIS that extends its capability beyond serving static HTML content. In this context, ASP, ASP.NET, ISAPI, and CGI all represent examples of different Web Server Extensions on IIS. ASP and ASP.NET are themselves implemented as ISAPI extensions on IIS. |
|
|