远程web.config加密问题 [英] Problem with remote web.config encryption

查看:59
本文介绍了远程web.config加密问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天



我用Google搜索无效,我想知道是否有人可以帮助我。我需要在c#中更改远程站点的web.config。然后加密web.config部分并能够解密它以再次进行更改。我们正在运行iis7。



我设法对远程web.config进行了更改,没有任何问题。但是只要我加密连接字符串部分然后尝试更新它。当web.config加密时,我得到配置部分加密不支持iis7当它没有加密时它可以工作。



我正在使用的代码是

Good Day

I have googled to no avail and I was wondering if anyone can help me. I need to change the web.config of a remote site in c#. Then encrypt the web.config section and be able to decrypt it to make changes again. We are running iis7.

I have managed to make changes to the remote web.config with no problem. But as soon as I encrypt the Connection string section and then try to update it. I Get "configuration section encryption is not supported iis7" when the web.config is Encrypted when it is not Encrypted it works.

The Code I am using is

ServerManager iisManager = new ServerManager();
  Microsoft.Web.Administration.Configuration config = iisManager.GetWebConfiguration(ddListSites.SelectedItem.Value.ToString());

                    ConfigurationSection connectionStringsSection = config.GetSection("connectionStrings");
                    ConfigurationElementCollection appSettingsCollection = connectionStringsSection.GetCollection();

                    foreach (ConfigurationElement conlist in appSettingsCollection)
                    {
                        string Name = conlist.Attributes[1].Value.ToString();
                        string Constring = conlist.Attributes[0].Value.ToString();
                        string ConstringAttributeName = conlist.Attributes[0].Name.ToString();

                        if (Name == ddlistConnections.SelectedItem.Text)
                        {

                            conlist.Attributes[0].Value = newconnection;
                            iisManager.CommitChanges();

                        }

                    }



我不能使用以下内容,因为它不是本地web.config






I cannot use the following because it is not a local web.config


Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
       //open the connection strings section
       ConfigurationSection section = config.GetSection("connectionStrings");

       //check to make sure it is not already encrypted
       if (!section.SectionInformation.IsProtected)
       {
           //encrypt it with RSA Protection
           section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
           //save the config file
           config.Save();
       }





要求是web.config必须加密



任何帮助或指示都会很高兴。



亲切的问候

Divan



The requirement is that the web.config must be encrypted

Any help or pointers would be gladly appreciated.

Kind regards
Divan

推荐答案

IIS7了解预加密的部分,但不支持通过管理对象进行部分加密...

仅手动支持部分加密 - 通过aspnet_regiis!您可以通过管理对象管理属性加密,如果它有帮助......
IIS7 understand pre-encrypted sections, but do not support section encryption via the management objects...
Section encryption supported only manually - via aspnet_regiis! You can manage attribute encryption via management objects, if it helps...


这篇关于远程web.config加密问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆