Stupid web.config mistake: Sections must only appear once per config file

Today’s stupid mistake comes to you via the web.config file in an ASP.NET 4 Web application project.

At runtime, when navigating to default.aspx, ASP.NET choked with this error message:

Parser Error Message: Sections must only appear once per config file.  See the help topic <location> for exceptions.

Source Error:

Line 14:     <location path="default.aspx">
Line 15:         <system.web>
Line 16:             <authorization>
Line 17:                 <allow users="*" />
Line 18:             </authorization>

“What’s the problem?”, I grumbled. “I’ve used the <location> element a million times to allow anonymous users to reach certain public pages in an app that otherwise requires authentication.”

The compiler doesn’t lie – but it does mislead you as to the exact spot.

More probing revealed a Copy/Paste error further on in the web.config.  You see, I had copied the aforementioned <location></location> node with the intention of inserting an exemption for another page, register.aspx. I hadn’t followed through with the change, and therefore had two <location path="default.aspx">  nodes. Dumb? Yup.

Once again, I reveal my idiocy to the world in hopes that my aggravation and lost time reduces yours.

Ken

4 Comments

  • Since my recent experiences with .htaccess files, I think the "web.config" idea is still superior to the pseudo XML style of those Apache .htaccess files.

  • Thanks for the post. The problem is not in making the making the mistake. It's not being able to find it when the compiler is giving you a hint about it. Happens once in a while to me. The best way to catch the error is to go play a game or have fun and come back the next day (when you are still energetic) and hunt for it. Of course, only if you are not working for someone.

  • how do i solve this error? Where do i place location tag?

  • In your web.cofig there are added same tag at twice remove one of them.

Comments have been disabled for this content.