Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have an old WebControl that needs to be updated to work with IIS 7.5.

In the control there is some code that checks if the Handler is registered in the Web.Config.
It opens the HandlerSection using
C#
System.Web.Configuration.HttpHandlersSection handlerSection = System.Web.Configuration.WebConfigurationManager.GetWebApplicationSection("system.web/httpHandlers") as System.Web.Configuration.HttpHandlersSection;
which works fine on IIS 6. But on IIS 7 and forward the Handler Section has been moved from <system.web><httpHandlers> to <system.webServer><handlers>
Changing the code to
C#
System.Web.Configuration.HttpHandlersSection handlerSection = System.Web.Configuration.WebConfigurationManager.GetWebApplicationSection("system.webServer/handlers") as HttpHandlersSection;
doesn't work, handlersection is null.

So, what am I doing wrong?

I've fiddled with it a bit and changing it to just
C#
System.Web.Configuration.HttpHandlersSection handlerSection = System.Web.Configuration.WebConfigurationManager.GetWebApplicationSection("system.webServer") as System.Web.Configuration.HttpHandlersSection;
gives me an InvalidCastException. "Unable to cast object of type 'System.Configuration.IgnoreSection' to type 'System.Web.Configuration.HttpHandlersSection'."
Posted
Updated 12-May-14 2:13am
v2
Comments
Kornfeld Eliyahu Peter 12-May-14 5:13am    
Read here: http://msdn.microsoft.com/en-us/library/vstudio/46c5ddfy(v=vs.100).aspx
Jörgen Andersson 12-May-14 5:24am    
Oh, I'm not having a problem registering the section, the control works just fine otherwise. It's the code that checks if the control is registered that doesn't work anymore.
Kornfeld Eliyahu Peter 12-May-14 6:04am    
Good! See this page, there is a sample code how to read handlers section...
http://www.iis.net/configreference/system.webserver/handlers#006
It a bit different from yours...
Jörgen Andersson 13-May-14 3:19am    
I've checked it through now and while the example given requests more permissions than I'm willing to give a website, there are other ways to use it that doesn't need it.
The real problem is that Microsoft.Web.Administration has a different purpose than System.Web.Configuration and therefore lacks a lot of functionality that I want.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900