ASP.NET 1.1 working with an ASP.NET 2.0 web.config file

In a recent post I described the trouble an asp.net 1.1 application has with a web.config file targeted at asp.net 2.0. The main problem is that the asp.net 1.1. runtime does not understand parts of the 2.0 web.config and crashes. My first solution was to move settings to the global 2.0 config. In a brilliant comment Joshua Flanagan suggested to bring the problem to its owner. His idea was to teach asp.net 1.1 the 2.0 specific sections and tell it to ignore them. This sounds more complicated than it is and works well.


For a good overview of the web.config in 1.x I again recommend James Avery little book,  I blogged before on that. The global configuration of asp.net 1.x is in the machine.config file in \WINDOWS\Microsoft.NET\Framework\v1.x\CONFIG. (Note that 1.x does not have a global web.config like 2.0). This file has a list of sections and the assemblies to handle the sections. The framework has a very handy handler, the IgnoreSectionHandler. Which does exactly what’s desired: nothing. This snippet tells asp.net to ignore the connectionstrings section



<?xml version=1.0 encoding=utf-8?>


<configuration>


 


  <configSections>


    <!– tell .NET Framework to ignore 2.0 sections –>


    <section


        name=connectionStrings


        type=System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089


        allowLocation=false />


 


    <!– tell .NET Framework to ignore CLR sections –>


    <section


        name=runtime


        type=System.Configuration.IgnoreSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089


        allowLocation=false />


    <section


        name=mscorlib


Entering it is easy, copy the runtime section, just below and change the name attribute. Asp.net has far more sections than 1.1, like the system.web.rolemanager and system.web.membership, which came by in the previous post. Add the sections as needed. Perhaps it would have been nice if there was an installation tool  which modifies the 1.x machine.config for all 2.0 specific sections. Hey MS, are you listening?


There is one incompatibility which is not handled. In 2.0 the configuration node has a namespace attribute.



<configuration xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0>


  <appSettings/>


  <connectionStrings>


1.x trips over that. Delete the attribute:



<configuration>


  <appSettings/>


  <connectionStrings>


Asp.net 2.0 works without it. Assigning a namespace might be useful for future versioning, but it hinders backward compatibility.

This entry was posted in ASP.NET. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Will C

    I saw this technique and tried it out. It worked great to use an IgnoreSectionHandler for the the ‘connectionStrings’ section in the 1.1 machine.config and I thought I was all set to put my 1.1 app under my 2.0 app. Then I added an IgnoreSectionHandler for ‘system.web.pages.namespaces’ and got the error “Child Nodes are not allowed.” Have you encountered that issue? Here is the code:


    Will

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    Afaik you can only apply a handler on a full section, not on a part (childnode). Correct me when I’m wrong. (and tell how to do it :) )

  • Fraknlin

    In case you haven’t found a solution to handling child nodes, try something such as this:

    In this manner, I can selectively ignore child nodes of

  • Franklin

    Rather it should be

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    thanks Franklin, that’s cool !

  • Ryan Lee

    Thanks Peter, and all other for your suggestions/work.
    I found a simpler way around the problem. It was almost an accident that I discovered it, but here it is…

    All Web.config’s will be read recursively back to the physical root from the origin (as you have explained) so that presents a problem when you need a virtual directory somewhere (anywhere) in the site. Wherever you input it, it will always be under the root, so it will have the same problem.

    I discovered that if I moved my root app to a sub-directory and then re-mapped the root of my site to that sub-directory (having had already mapped the problematic virtual sub-directory first) that both sites now worked and only one or the other web.config files were parsed.

    The web apps behave exactly as they should, because they are “virtually” in the same places as they were before. :-)

    BTW, my root web-app is DotNetNuke 4 (using asp.net 2.0) and my custom web-app (asp.net 1.1) in the virtual directory.

    I had already switched the 1.1 virtual directory to use the appropriate framework version in the asp.net tab (properties) prior to encountering the problem at hand.

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    thanks for your approach but I’m afraid it will not be that easy in my scenario to implement it. The 2.0 app is the www root of my public site. The 1.1 apps are Exchange owa and oma. Once these are running you don’t want to start fiddeling with them :) For now I’m quite happy with my solution, it has been running stable for months.

  • http://gabewishnie.blogspot.com gabe

    I dont think this method will work if you define a custom section group in the web.cong. .NET 2.0 supports a new attribute (type) on the section group where 1.1 did not. And telling 1.1 to ignore the section group section is not going to fly.

    So I think with any sections that have new attributes that you cannot ignore you are going to run into an issue. Is this correct?

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    There is only one way to find out: juts try :) You will know the moment the 1.1. app tries to load.

    But I think you are right and 1,1 will trip.

  • kevin

    This technique fails if a new attribute is part of the 2.0 definition. As suggested by gabe.

  • kendall

    a solution to the child nodes issue is to create a “pages” _sectionGroup_ within the “system.web” sectionGroup, and then have a section for the “namespaces” child node. so far, this is working as expected. note that the sectionGroup for system.web already exists so you should put the “pages” sectionGroup within that. also note that by default there is a “pages” section within system.web that needs to be moved to the new “pages” sectionGroup. below is an example:

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    Thanks, that’s a welcome addition :)

  • Chris Larson

    I had the same probem, and I tried some of the approaches described above, none of which worked (separate app pools & ignore section).

    I also have the problem that my root web is the public site, so separate domains won’t work for me.

    I then found this: http://www.velocityreviews.com/forums/t372410-running-a-11-app-under-a-20-root-web.html, which did work. Note that there is not answer to the basic question he poses — is there a problem doing this?

    One more approach to working around this problem.

    Chris

  • Duane McDowell

    We had the same problem described in your entry here.

    A bit of information about our situation.. we had a 1.1 web application that we decided to migrate to dotnet 2.0. When moving to the 2.0, we added some AJAX controls from the new ajax control library provided by microsoft. Our Application also uses Reporting Services 2000 in a virtual directory under the root. I found your blog entry and your blog helped me understand what was going on with our Windows 2003/IIS 6.0 development server that was causing our Reporting Services 2000 to generate errors.

    I discovered once I used the technique described here to tell Framework 1.1 to ignore the sections, that I still had a problem with the ajax sections of the web applications web.config. Without the Ajax sections, Reporting Services would work.. With them I would get errors.

    After some trial and error, I was able to get Reporting Services 2000 virtual directories to work if I took the ajax sections out of the application web.config and move them to the dotnet 2.0 framework web.config and the framework machine.config.

    The question I have is.. is there a better way of handling this than the way I came up with?

  • http://codebetter.com/blogs/peter.van.ooijen pvanooijen

    You’re lucky, it is working !

    Sorry no, this post and the comments are everything and more I know off

  • Nnada kumar

    Can i ignore child elements of and

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    1.1. does understand these tags. But when 1.1 whil try to load a 2.0 handler or module assembly you’re most likely in trouble.

  • http://tkomala1981@yahoo.co.in Komala

    I am facing a problem when I tried to host the asp.net application in windows server 2003.
    VB cum ASp.net front end and Ms Access as back end

    It is showing the error : “Child nodes are not allowed”
    for the tag

    But the same web.config file didnt show such an error when I tried to host in win XP OS.

    Kindly explain me whats the problem and what should be done to avoid to host the web application without trouble.

    Thanks
    regards
    Komal

  • http://petersgekko.codebetter.com pvanooijen

    Sounds like the IIS setting for the asp.net version is wrong. Check that in the ASP.NET tab of the IIS admin