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