|
|
|
start date: Mon, 20 Aug 2007 10:20:02 -0700,
posted on: microsoft.public.dotnet.framework.aspnet
back
| Thread Index |
|
1
Chuck P am
|
|
2
(Steven Cheng[MSFT])
|
|
3
Chuck P am
|
|
4
(Steven Cheng[MSFT])
|
ConfigurationPropertyAttribute.IsRequired Property
I was creating a Custom Configuration section in my web.config.
I noticed that if I set a property like:
[ConfigurationProperty("EmailAuthorizationFailures", IsRequired = true)]
<MySection
EmailAuthorizationFailures="true"
/>
and I neglected to put the entire MySection in the web.config. I don't get
an error. Additionally if I actually read the section using
GetConfig("MySection") it comes back full of values (DefaultValue or
ValueType defaults ). I thought it would be NULL.
I would like to throw an exception if the user forgets to put in the
section in the web.config.
Is their a way to test for the missing section?
thanks,
Date:Mon, 20 Aug 2007 10:20:02 -0700
Author:
|
RE: ConfigurationPropertyAttribute.IsRequired Property
Hi Chuck,
As for the "how to test the missing of a configuration section in .net
config file", I think it a good question. However, based on my research,
the current .NET configuration settings model doesn't provide support of
detecting the existence of a configuration section automatically(only the
detection of a sub section properrty is supported). This limitation is due
to the following design of the configuration section processing mechanism:
** When .net application runs, it will not always load all the
configuration settings at one time or at the startup time. The loading of
each configuration section is on-demand and may occur at different time.
Thus, it won't be convenient to check all the potential configsection's
existence.
** So far <configSections><section> element only support the definition of
the scope and modify-behavior of the registered section, haven't provided
setting to control the existence detection
For your scenario, if you do need to take care of some certain custom
configuration's existence, I think you may consider manually use the
configuration API to query the certain section in code or use XML API to
perform xml query against the app.config file.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Tue, 21 Aug 2007 03:30:34 GMT
Author:
|
RE: ConfigurationPropertyAttribute.IsRequired Property
Thanks,
I'll think I will use a little hack.
Create a setting. IhaveBeenSpecified default =false.
When I read the settings in code if it is false, I'll throw an exception.
"Steven Cheng[MSFT]" wrote:
> Hi Chuck,
>
> As for the "how to test the missing of a configuration section in .net
> config file", I think it a good question. However, based on my research,
> the current .NET configuration settings model doesn't provide support of
> detecting the existence of a configuration section automatically(only the
> detection of a sub section properrty is supported). This limitation is due
> to the following design of the configuration section processing mechanism:
>
> ** When .net application runs, it will not always load all the
> configuration settings at one time or at the startup time. The loading of
> each configuration section is on-demand and may occur at different time.
> Thus, it won't be convenient to check all the potential configsection's
> existence.
>
> ** So far <configSections><section> element only support the definition of
> the scope and modify-behavior of the registered section, haven't provided
> setting to control the existence detection
>
> For your scenario, if you do need to take care of some certain custom
> configuration's existence, I think you may consider manually use the
> configuration API to query the certain section in code or use XML API to
> perform xml query against the app.config file.
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
>
> ==================================================
>
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
>
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
>
>
Date:Tue, 21 Aug 2007 06:26:02 -0700
Author:
|
RE: ConfigurationPropertyAttribute.IsRequired Property
Thanks for your reply Chuck,
Yes, the method you mentioned should be a good trick to help perform such
detection. Thanks for sharing it with us.
BTW, I also think this is a reasonable feature and recommend you submit it
to our product feedback site:
https://connect.microsoft.com/feedback/default.aspx?SiteID=210&wa=wsignin1.0
Thanks for your posting!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Date:Wed, 22 Aug 2007 06:01:14 GMT
Author:
|
|
|