I've Encrypted connectionString section in web.config using ASPNET_REGIIS successfully. however i've done this on my local machine.
When I tried to publish website on a shared hosting server I received a configuration file error.
Is there any way I could Encrypt on a shared hosting server using ASPNET_REGIIS without access to the physical server machine?
Thanks.
I found a solution, Might not be the best but I feel okay with it..
I encrypted web.Config once, using the first function. I decrypt it on each call.
public static void EncryptConnString()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
ConfigurationSection section = config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
config.Save();
}
}
public static MySqlConnection DecryptConnString()
{
MySqlConnection conn = new MySqlConnection();
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
ConfigurationSection section = config.GetSection("connectionStrings");
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["DatabaseName"].ConnectionString);
return conn;
}
else
return null;
}
(using MySql)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.