Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

560 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

FIGURE 24-7 Viewing a list of maintenance tasks

Managing Internet Information Server

You can optimize the SkyShark Airlines Web application by modifying the Web.Config file or by using Internet Services Manager, which is the administration tool for IIS (Internet Information Server). Internet Services Manager is an MMC (Microsoft Management Console) based console that can be used to manage IIS Server. By using Internet Information Services, you can add and remove Web sites, control access to Web sites, and start and stop the IIS server. In this section, you will examine the steps to configure HTTP error pages and Web ser ver log files for the SkyShark Airlines application. To configure the error pages and Web server log files, I will use the Web.Config file and Internet Information Services MMC add-in, respectively.

Configuring IIS Error Pages

A default set of error pages is associated with IIS. Error pages are HTML pages that are numbered according to the error that they represent.These pages are displayed when HTTP errors occur while browsing the Web site. For example, if IIS encounters an error while processing a request, an internal server error is generated, which is the HTTP error number 500. Similarly, if the user requests a Web page that does not exist, error 404 is generated, which is shown in Figure 24-8.

ADMINISTERING THE APPLICATION

Chapter 24

561

 

 

 

 

FIGURE 24-8 A default error message

Notice that in the preceding figure, I browsed for the Web form http:// npandey-d185/SkyShark/CreateNewReservation.aspx that does not exist in the application. You can change the default error pages that are associated with IIS. For example, you can create a new Web page for the 404 error. The Web page might provide links to another page of the Web site or enable the user to send an e-mail message to the network administrator of SkyShark Airlines.

The next section will customize the 404 error page for the Web site. I have created a simple HTML page to which the user should be redirected if a Web page does not exist. The code for the page is given as follows:

<html> <head>

<title>Page Not Found</title> </head>

<body>

<p align=”center”><b><FONT face=”MS Sans Serif” size=”5”>Page Not Found.</FONT></b></p>

<HR>

<p>The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please make sure that it is spelled correctly or select one of the options given below:</p>

562 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

<p>Report a bug to the <a href=”mailto:admin@skyshark.com”>System administrator</a></p>

<p>Browse to default page of <a href=”http://npandey-d185/SkyShark”>SkyShark</a> Airlines</p>

<HR>

<p><font face=”Book Antiqua”><FONT size=”2”>(C) </FONT><a href=”http://npandey-d185 /skyshark”>

<FONT size=”2”>SkyShark Airlines</FONT></a><FONT size=”2”> 20012002</FONT></font></p>

</body> </html>

Save the file in the root directory of the SkyShark Airlines application with the name Error404.htm. To associate the HTML page with the 404 error, you need to make configuration changes in the Web.Config file.The Web.Config file is an XML-based file that contains information pertaining to the configuration of the application, such as the authentication mode that is supported by the application and the mode of tracking session state of the application.

The Web.Config file includes the <customError> element that is used for configuring custom error messages for the application. The <customError> element has two attributes that pertain to custom error messages. These attributes are described in the following list:

mode. The mode attribute is used to enable or disable custom error messages for the Web site.This attribute can have the values On, Off, or RemoteOnly. When the value is On, custom error messages are enabled in the application. Similarly, the value Off disables custom error messages on the Web site. When the value is RemoteOnly, custom error messages are displayed only for remote requests to the Web application.

defaultRedirect. The defaultRedirect attribute is used to identify the location and name default error page that is associated with the Web application.

The <customError> element includes a child element <error> that is used to configure error pages for specific errors that occur in the Web application. Thus, if you need to specify a specific error page for the 404 error, you need to use the <error> element. The <error> element includes two attributes: statusCode and redirect. These attributes are described in the following list:

ADMINISTERING THE APPLICATION

Chapter 24

563

 

 

 

 

statusCode. The statusCode attribute is used for specifying the error number with which you are associating the error page.

redirect. The redirect element is used to specify the custom page that you want to display when the application encounters the error.

To associate your error page with the 404 error, open the Web.Config file in Visual Studio .NET. The Web.Config file is located in the root directory of the Web application. In the Web.Config file, locate the <customError> element and replace it with the following code:

<customErrors mode=”On” defaultRedirect=”AllErrors.htm”>

<error statusCode=”404” redirect=”Error404.htm”/>

</customErrors>

Save the Web.Config file. After you associate the custom error page with error 404, the error message shown in Figure 24-9 is generated when a user requests a Web page that does not exist.

FIGURE 24-9 Displaying custom error messages

Managing Web Server Log Files

IIS generates log files for all requests that are processed by it. Log files can help you track the users who have visited your Web site or provide useful information about the performance of the IIS server and your application.

564 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

You can configure IIS to create log files in a number of formats. Some of the commonly used formats for generating log files are given as follows:

W3C Extended Log File. This format creates ASCII files that contain one entry per request that is processed by IIS. Each entry has a number of fields that provide information about the different parameters of the request. For example, the #Date field indicates the date on which the first entry in the log file was made.

Microsoft IIS Log. This format also creates ASCII files that record basic information about each Web request, such as the user’s IP address and the number of bytes that were exchanged in processing the request. The Microsoft IIS Log format can be exported to other applications like Microsoft Excel, Microsoft Access, or another RDBMS (Relational Database Management System) for proper utilization.

ODBC Logging. This format is used to record log file data in ODBC (Open Database Connectivity) compliant databases, such as Microsoft SQL Server. This is a convenient format for analyzing log file data because data from SQL Server databases can be presented in a number of ways.

To configure the location of log files and the format in which logs should be created, you need to use the MMC-based administration console for Internet Information Services. To access the MMC-based administration console for Internet Information Services, perform the following steps:

1.Open the Programs menu by clicking on Start and then selecting Programs.

2.On the Programs menu, point to Administrative Tools and click Internet Services Manager to open the Internet Information Services window.

3.In Internet Information Services, right-click on Default Web Site and select Properties. The Default Web Site Properties dialog box will appear.

4.In the Default Web Site Properties dialog box, select the required logging format from the Active log format list.

5.Click on Properties to configure the location and the frequency with which the log files should be generated. The Extended Logging Properties dialog box will appear.