I am able to configure the Connection String Encryption using the aspnet_regiis.exe
command. Now I have created the Configuration Section on which it is added Custom Configuration Element Collection and this will store the value of Connection Information.
namespace ExpressSnapSortCreation
{
/// <summary>
/// This Class hold the the Collection of Cofigration key
/// </summary>
internal class ServerReplicationsCollection : ConfigurationElementCollection
{
/// <summary>
/// This Will return the ConfigurationElement
/// </summary>
/// <returns>ConfigurationElement</returns>
protected override ConfigurationElement CreateNewElement()
{
return new ServerReplicationsElement();
}
/// <summary>
/// Get Element BY key
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
protected override object GetElementKey(ConfigurationElement element)
{
return ((ServerReplicationsElement)element).Name;
}
/// <summary>
/// This is override on the Elements
/// </summary>
public class ServerReplicationsElement : ConfigurationElement
{
/// <summary>
/// Name of the Element
/// </summary>
[ConfigurationProperty("name", IsRequired = true)]
public string Name
{
get { return (string)this["name"]; }
set { this["name"] = value; }
}
/// <summary>
/// Data base name
/// </summary>
[ConfigurationProperty("connectionString", IsRequired = true)]
public string ConnectionString
{
get { return (string)this["connectionString"]; }
set { this["connectionString"] = value; }
}
/// <summary>
/// Data base user name
/// </summary>
[ConfigurationProperty("providerName", IsRequired = true)]
public string ProviderName
{
get { return (string)this["providerName"]; }
set { this["providerName"] = value; }
}
/// <summary>
/// Display Order
/// </summary>
[ConfigurationProperty("order", IsRequired = false)]
public int Order
{
get { return (int)this["order"]; }
set { this["order"] = value; }
}
}
}
}
This is the code of the Section Creation
class ServerReplications : ConfigurationSection
{
/// <summary>
/// The name of this section in the app.config.
/// </summary>
public const string SectionName = "ReplicationConfigurationSection";
/// <summary>
/// Replication data base name
/// </summary>
private const string ReplicationCenterCollectionName = "ReplicationDataBases";
[ConfigurationProperty(ReplicationCenterCollectionName)]
[ConfigurationCollection(typeof(ServerReplicationsCollection), AddItemName = "add")]
public ServerReplicationsCollection ReplicationDataBases { get { return (ServerReplicationsCollection)base[ReplicationCenterCollectionName]; } }
}
This is my App Config file.
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="ReplicationConfigurationSection"
type="ExpressSnapSortCreation.ServerReplications, ExpressSnapSortCreation" />
</configSections>
<ReplicationConfigurationSection>
<ReplicationDataBases>
<add name="ApplicationServices" connectionString="Data Source=PC-002\SQLEXPRESS2014;Initial Catalog=AML25;Persist Security Info=True;User ID=sa;Password=StItS!@#SeRvErPC-003" providerName="System.Data.SqlClient" order="1" />
<add name="ApplicationServices2" connectionString="Data Source=PC-004\SQLEXPRESS2014;Initial Catalog=AML26;Persist Security Info=True;User ID=sa;Password=StItS!@#SeRvErPC-002" providerName="System.Data.SqlClient" order="2" />
</ReplicationDataBases>
</ReplicationConfigurationSection>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
In the Application we are getting the The value of the connection string. Due to Security purpose We can't Show the Data in App.config value. then it is required to encrypt the below Section
This is the first command I used
aspnet_regiis.exe -pef "ReplicationConfigurationSection" "C:\Users\mukesh.singh\Documents\Visual Studio 2015\Projects\AML\ExpressSnapSortCreation"
Got Error Convert the file name "app.config" to "Web.config"
An error occurred creating the configuration section handler for ReplicationConfigurationSection: Could not load file or assembly 'ExpressSnapSortCreation' or one of its dependencies. The system cannot find the file specified. (C:\Users\mukesh.singh\Documents\Visual Studio 2015\Projects\AML\ExpressSnapSortCreation\bin\Debug\web.config line 4)
Could not load file or assembly 'ExpressSnapSortCreation' or one of its dependencies. The system cannot find the file specified. Failed!
- After changed
Could not load type 'ExpressSnapSortCreation.ServerReplications' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
I tried this combination also
aspnet_regiis.exe -pef "ExpressSnapSortCreation.ServerReplications/ExpressSnapSortCreations" "C:\Users\mukesh.singh\Documents\Visual Studio 2015\Projects\AML\ExpressSnapSortCreation