0
votes

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.

1
In most cases you cannot do this on your own and rely on the service provider. Give them a call.Lex Li
They suggested me to upgrade to a virtual server. Is it even possible to install visual studio on a virtual server?Osher Levy

1 Answers

0
votes

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)