我已经成功使用 ASPNET_REGIIS 加密了 web.config 中的 connectionString 部分。但是我已经在我的本地机器上完成了这个。
当我尝试在共享托管服务器上发布网站时,我收到了配置文件错误。
有什么方法可以在不访问物理服务器机器的情况下使用 ASPNET_REGIIS 在共享托管服务器上加密?
谢谢。
我已经成功使用 ASPNET_REGIIS 加密了 web.config 中的 connectionString 部分。但是我已经在我的本地机器上完成了这个。
当我尝试在共享托管服务器上发布网站时,我收到了配置文件错误。
有什么方法可以在不访问物理服务器机器的情况下使用 ASPNET_REGIIS 在共享托管服务器上加密?
谢谢。
我找到了一个解决方案,可能不是最好的,但我觉得还可以..
我使用第一个函数加密了 web.Config 一次。我在每次通话时解密它。
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;
}
(使用 MySql)