
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Checking out a Web Server’s Custom Error Pages
|
825
14.18 Checking out a Web Server’s Custom Error Pages
Problem
You have an application that needs to know what custom error pages are set up for
the various HTTP error return codes on a given IIS server.
Solution
Use the System.DirectoryServices.DirectoryEntry class to talk to the Internet Infor-
mation Server (IIS) metabase to find out which custom error pages are set up. The
metabase holds the configuration information for the web server.
DirectoryEntry
uses the Active Directory IIS service provider to communicate with the metabase by
specifying the
"IIS" scheme in the constructor for the DirectoryEntry.
// This is a case-sensitive entry in the metabase.
// You'd think it was misspelled but you would be mistaken...
const string WebServerSchema = "IIsWebServer";
// Set up to talk to the local IIS server.
string server = "localhost";
// Create a dictionary entry for the IIS server with a fake
// user and password. Credentials would have to be provided
// if you are running as a regular user.
using (DirectoryEntry w3svc =
new DirectoryEntry(
string.Format("IIS://{0}/w3svc", server),
"Domain/UserCode", "Password"))
{
Once the connection is established, the web server schema entry is specified to show
where the IIS settings are kept (
IIsWebServer ...