Question : HOWTO: Programatically Configure Error Pages Features Settings in IIS 7.0

I would like to programmatically (C#) configure IIS 7.0 for a given application, to do the equivalent of manually:

Computer Management => Services and Applications => Internet Information Services => Sites => Default Web Site => ApplicationName => Error Pages
Clicking "Edit Feature Setttings..."
Under "Error Reponses" set "When the server encounter an error, return:" to "Custom error pages".

Thanks,
Michael

Answer : HOWTO: Programatically Configure Error Pages Features Settings in IIS 7.0

u can custom your error pages using ServerManager (Microsoft.Web.Administration.dll)
checkout the code snippet.
take a look at http://www.iis.net/ConfigReference/system.webServer/httpErrors/error for further reading.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetApplicationHostConfiguration();
         ConfigurationSection httpErrorsSection = config.GetSection("system.webServer/httpErrors");
         ConfigurationElementCollection httpErrorsCollection = httpErrorsSection.GetCollection();

         ConfigurationElement errorElement = httpErrorsCollection.CreateElement("error");
         errorElement["statusCode"] = 404;
         errorElement["subStatusCode"] = 5;
         errorElement["prefixLanguageFilePath"] = @"%SystemDrive%\inetpub\custerr";
         errorElement["path"] = @"404.5.htm";
         httpErrorsCollection.Add(errorElement);

         serverManager.CommitChanges();
      }
   }
}
Random Solutions  
 
programming4us programming4us