I have a configuration class that maps web.config, something like this:
< Code> public class site configuration topic: configuration sign {{configuration property ("defaultConnectionStringName", DefaultValue = "LocalSqlServer")) Public string DefaultConnectionStringName {get {return (string) base ["defaultConnectionStringName"]; } Set {base ["defaultConnectionStringName"] = value; }} [Configuration property ("module", Israquired = true)] Public module Element module {Return error (module element) ["module"]; }}} Public class module element: Configuration element {{ConfigurationProperty ("connectionstringName")} public string connection string name {{{return {string} base ["connectionstringName"]; } Set {base ["connectionStringName"] = value; }} Public string ConnectionString {get {string str; If (string.IsNullOrEmpty (this.ConnectionStringName)) receive {{str = // SiteConfigurationSetection from DefaultConnectionStringName; } Else str = this.ConnectionStringName; Return WebConfigurationManager.ConnectionStrings [str]. ConnectionString; }}}
Meaning if the value of the connection string name in the module section in the web.config file is missing, the value should be read from the configuration.
How to do this?
This will depend on the name of the tag in your section.
Var CS = ((SiteConfigurationSection) WebConfigurationManager .GetSection ("mySectionTag")). DefaultConnectionString;
Comments
Post a Comment