Tags down


How do I define custom web.config sections with potential child elements and attributes for the properties?

By : Paul Kostenko
Date : July 28 2020, 05:00 PM
Does that help Using attributes, child config sections and constraints
There is also the possibility to use attributes which automatically takes care of the plumbing, as well as providing the ability to easily add constraints.
code :
namespace Ani {

    public sealed class MailCenterConfiguration : ConfigurationSection
        [ConfigurationProperty("userDiskSpace", IsRequired = true)]
        [IntegerValidator(MinValue = 0, MaxValue = 1000000)]
        public int UserDiskSpace
            get { return (int)base["userDiskSpace"]; }
            set { base["userDiskSpace"] = value; }
    <!-- Mailcenter configuration file -->
    <section name="mailCenter" type="Ani.MailCenterConfiguration" requirePermission="false"/>
<mailCenter userDiskSpace="25000">
     port="366" />
public sealed class MailCenterConfiguration : ConfigurationSection
    [ConfigurationProperty("mail", IsRequired=true)]
    public MailElement Mail
        get { return (MailElement)base["mail"]; }
        set { base["mail"] = value; }

    public class MailElement : ConfigurationElement
        [ConfigurationProperty("host", IsRequired = true)]
        public string Host
            get { return (string)base["host"]; }
            set { base["host"] = value; }

        [ConfigurationProperty("port", IsRequired = true)]
        [IntegerValidator(MinValue = 0, MaxValue = 65535)]
        public int Port
            get { return (int)base["port"]; }
            set { base["port"] = value; }
private static MailCenterConfiguration instance = null;
public static MailCenterConfiguration Instance
        if (instance == null)
            instance = (MailCenterConfiguration)WebConfigurationManager.GetSection("mailCenter");

        return instance;
public void SendMail()
    MailCenterConfiguration conf = MailCenterConfiguration.Instance;
    SmtpClient smtpClient = new SmtpClient(conf.Mail.Host, conf.Mail.Port);
protected void Application_ Start(object sender, EventArgs e)

Share : facebook icon twitter icon

Create a custom block in web.config for web.config with a random number of elements

By : dhananjay singh
Date : March 29 2020, 07:55 AM
will help you To create a structure of add/clear/remove child elements the type matching the MySettings element needs to derive from ConfigurationElementCollection.

Custom web.config sections (ASP.NET)

By : senthil
Date : March 29 2020, 07:55 AM
Does that help I think you need to create a property decorated with the ConfigurationCollectionAttribute attribute. I scanned your code and didn't see a reference to it anywhere.
The MSDN link for once actually has a useful example. I recently put together a custom config section myself, and found that page entirely adequate. See my question for how to enable Intellisense support for your config section in Visual Studio.

How-to Transform Web.config Custom Sections With MSDeploy?

By : user2502948
Date : March 29 2020, 07:55 AM
help you fix your problem Write transformation in config transformation file (web.config.release)
code :
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <data useCache="false" xdt:Transform="SetAttributes(useCache)" />

Why do I have to specify the assembly in my app.config but not for my web.config when using custom sections

By : peterff
Date : March 29 2020, 07:55 AM
it helps some times It depends on the host that executes your code.
Without extra plumbing you'll find that in the inner workings of the Configuration namespace the type attribute is fed into the static method Type.GetType(string typeName).

Encrypting custom sections of a web.config

By : jmlab
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Here's another workaround for this issue (found at http://www.dotnetnoob.com/2013/01/how-to-encrypt-custom-configuration.html). Comment out the section element for the custom section under the configSections element (/configuration/configSections) before running the aspnet_regiis command and the custom section should get encrypted.
Related Posts Related Posts :
  • Entity Framework Core disable recursive retrieval of information in .Include() function
  • Add/Edit/Delete buttons for Telerik RadTreeView control
  • 'Procedure or function 'GenerateTest' expects parameter '@questionnaireID', which was not supplied.'
  • Can ASP.NET target .net core?
  • What are effective options for embedding video in an ASP.NET web site?
  • Visual Studio "Unable to start debugging on the web server. The web server did not respond in a timely manner."
  • Tracking state using ASP.NET AJAX / ICallbackEventHandler
  • ASP.NET Display SVN Revision Number
  • ASP.NET URL Rewriting
  • Easy way to AJAX WebControls
  • Are Multiple DataContext classes ever appropriate?
  • Triple Quotes? How do I delimit a databound Javascript string parameter in ASP.NET?
  • ASP.NET built in user profile vs. old style user class/tables
  • Bandwith throttling in IIS 6 by IP Address
  • ASP.Net Custom Client-Side Validation
  • Checklist for IIS 6/ASP.NET Windows Authentication?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org