fbpx

WebConfigurationManager.OpenWebConfiguration()

Overlapping colored triangles

I just finished banging my head against the wall for many hours tracking down an obscure problem using OpenWebConfiguration() with custom ConfigSection's that use OnDeserializeUnrecognizedAttribute(). Although I'm still not sure why, the following is incorrect:

Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~/web.config");

Instead, you need to use:

Configuration configuration = WebConfigurationManager.OpenWebConfiguration( HttpContext.Current.Request.ApplicationPath);

The first one seems to work, but your ConfigurationElement loses the values of any properties set by OnDeserializeUnrecognizedAttribute(). For some reason, your constructor for your ConfigurationElement's get called twice.
It's all the more frustrating because the Windows Service / Console Application version OpenExeConfiguration() worked correctly!

About the Author:

Visionfriendly.com

Visionfriendly.com

VisionFriendly.com has been building successful websites for over 20 years and covers all areas of website design, development and marketing with creative custom web designs and a robust in-house team of programmers to get your web marketing to work exactly the way you need it to.

Share On:

Share on facebook
Share on twitter
Share on linkedin

Comments:

Leave a Comment

Your email address will not be published. Required fields are marked *

Copyright © 2021, All Rights Reserved
Tri Colored Triangles
Scroll to Top

Take your business to the

Next Level!

Visionfriendly.com has the right team to make your business stand out from other professional websites.

Ready For Takeoff?

A Completely Customized
Digital Marketing Experience

We'll be in touch within one business day to discuss your goals and create a personalized plan that fits both you and your business.

Let’s start a Conversation