822 Chapter 16 • Administration of an IIS 7.0 Web Server
To create an HTTP 500 Error for All ASP.NET Pages:
1. Click the server in IIS Manager.
2. On the IIS Manager server home page, double-click Failed Request Tracing, as shown
in Figure 16.6.
Figure 16.6 IIS Manager Failed Request Tracing
3. Click Add under Actions to start the Add Rule Wizard.
4. Select the content you would like traced—for example, ASPX pages (e.g., ASP.NET
requests).
5. Choose what criteria, either HTTP status code or time-taken, to trace requests. Select 500
and click Next.
6. Select what providers to choose from—in your case, pick all providers, including ASP,
ISAPI Extension, and WWW Server, as shown in Figure 16.7.
7. Click Finish.
Administration of an IIS 7.0 Web Server • Chapter 16 823
Figure 16.7
SOME INDEPENDENT ADVICE
In Windows Vista, the ASP.NET Provider is missing from IIS Manager. This provider exists in the confi guration and is available. In a recent blog post, Microsoft acknowledged this problem and displays how to correct it. For more information, see http://blogs.iis.net/chrisad/archive/2007/04/10/tracing-asp-net-provider-on- windows-vista.aspx.
Accessing Information Using AppCmd.exe AppCmd.exe is a convenient utility offered as an alternative to using IIS Manager, writing code, or building a script. Sometimes, you may be interested in making one or two changes to IIS’s confi guration but don’t want to click this or that in IIS Manager. Or maybe the actual confi guration
824 Chapter 16 • Administration of an IIS 7.0 Web Server
isn’t even available in IIS Manager, leaving you with no other choice. AppCmd solves this problem by using a familiar approach that employs verbs and objects. It combines much of the past power of the Visual Basic scripts (.vbs) shipped with IIS while providing a much more powerful functionality than ever offered by these scripts. Understanding how to use it will prove a strong and useful tool in managing your IIS servers.
BEST PRACTICES ACCORDING TO MICROSOFT
IIS 7.0 supports direct editing of the confi guration fi les, including applicationHost. confi g and web.confi g fi les. This is a powerful ability considering that you can use your favorite text editor to build your custom server’s confi guration.
However, it is not recommended you directly edit the confi guration using tools such as Notepad without fi rst testing that your confi guration is valid on your Web server. When using the text editor, there is no validation that your confi guration is correct, something which can possibly render your Web server, sites, or applications unavailable. This is where administration tools such as AppCmd.exe come in handy. They will not write invalid confi gurations but instead will return an error.
SOME INDEPENDENT ADVICE
AppCmd.exe does not work remotely. In order to successfully use AppCmd.exe, you must connect directly to your IIS 7.0 server. This is capable of being done using Terminal Services, such as using the command mstsc /console /v:yourIIS7Server, where yourIIS7Server is the name of your Web server.
An Introduction to AppCmd.exe In IIS 6.0, you had a large list of toolsets available to you to make changes at the command line to the confi guration. These were included in various Visual Basic scripts (.vbs) located in %windir%\system32 or in %systemdriver%\inetpub\adminscripts. The downside, though, was that they were specialized and each had different verb syntaxes and object manipulation styles. In IIS 7.0, your command-line experience is combined to a single application called AppCmd.exe. In this section, you are introduced to this powerful command-line tool aimed at simplifying your experience.
Administration of an IIS 7.0 Web Server • Chapter 16 825
Server Management Objects and Commands AppCmd allows you to create/confi gure Web sites, applications, application pools, and virtual directories. You can start and stop sites, recycle application pools, list worker processes, and examine currently executing requests. You can also search, manipulate, import, and export IIS and ASP.NET confi guration data.
SOME INDEPENDENT ADVICE
AppCmd.exe is not located in the system path, but instead in %windir%\ system32\inetsrv. If you want quick access to the IIS 7.0 confi guration runtime information, add inetsrv to the system path.
Command syntax is based on server management objects that expose methods to perform actions
and properties that refl ect the current state. Most objects provide list, add, and delete methods. Site objects have start/stop methods and properties that can be read, written, or searched. All commands provide a list of object instances and property values.
You execute AppCmd commands on server management objects with parameters to control
command behavior, such as the following:
APPCMD
To use AppCmd in changing directories, type: set path=%path%;%windir%\system32\inetsrv If you’re not logged on as a member of the Administrator group, run this command in an elevated cmd window from Start | All Programs | Accessories | Command Prompt. Right-click and choose Run as administrator.
LIST Displays all objects on the machine. Optional
826 Chapter 16 • Administration of an IIS 7.0 Web Server
The Site object supports START and STOP commands.
that search objects or manipulate properties allow properties specifi ed as a parameter. Creating Web Sites As we showed earlier, you can use IIS Manager to create Web sites. However, in some cases you might want an easier way to do this other than using a user interface. AppCmd.exe fi lls this void nicely and you can quickly get a site up and running using AppCmd.exe.
Before starting, you must have the name, path, and bindings to successfully create a new Web site
with a root Web application using AppCmd.
To create a new Web site using AppCmd.exe, type the following:
AppCmd add site /name:“My First AppCmd Website” /bindings:http/*:80:www.myfi rstsite.com
SITE Administration of virtual sites APP Administration of applications VDIR Administration of virtual directories APPPOOL Administration of application pools CONFIG Administration of general confi guration sections BACKUP Management of server confi guration backups WP Administration of worker processes REQUEST Display of active HTTP requests MODULE Administration of server modules TRACE Management of server trace logs
Creating Virtual Directories As we said earlier, virtual directories are an important concept in IIS 7.0 because they are the defi nition of a root application. Thus, although we have created a new site in the preceding example, we haven’t defi ned a new root application. We will do so in this example. If you do not defi ne an applica- tion, or virtual directory physical path, then the site will run as part of IIS 7.0’s default application pool.
AppCmd add site /name:“My First AppCmd Website” /bindings:http/*:80:www.myfi rstsite.com /physicalPath:“c:\inetpub\myfi rstsite”