[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

get the handler mappings from iis7 using asp.net

Ok, here is the question. Can I get the handler mappings from the iis7 that is config for my website hosted on iis using asp.net coding. Lets say I want to get all the handler mappings, then I want to add them to my web.config later to move to another hosting server and migrate the config from the iis7, so I donĀ“t get errors about handler mappings.
0
rafaelrgl
Asked:
rafaelrgl
  • 2
1 Solution
 
Bob LearnedCommented:
I believe that you can use the Microsoft.Web.Administration.ServerManager to get that information:

using (ServerManager serverManager = new ServerManager())
            {
            SiteCollection sitecollection = serverManager.Sites;

            Configuration webConfig = serverManager.GetWebConfiguration("Default Web Site");
            ConfigurationSection handlersSection = webConfig.GetSection("system.webServer/handlers");
            ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();

            foreach (var handler in handlersCollection)
            {
                Console.WriteLine(handler.GetAttributeValue("path"));

            }
        }

Open in new window

0
 
Bob LearnedCommented:
VB.NET:

Using serverManager As New ServerManager()
	Dim sitecollection As SiteCollection = serverManager.Sites

	Dim webConfig As Configuration = serverManager.GetWebConfiguration("Default Web Site")
	Dim handlersSection As ConfigurationSection = webConfig.GetSection("system.webServer/handlers")
	Dim handlersCollection As ConfigurationElementCollection = handlersSection.GetCollection()

	For Each handler As var In handlersCollection

		Console.WriteLine(handler.GetAttributeValue("path"))
	Next
End Using

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now