0

我在 dll 中有一个类,该类具有以下写入注册表的方法:

public Boolean WriteDBConnectionInfoToRegistry(string txtDSN, string txtServer, string txtDatabase, string txtUser, string txtPassword, bool trusted)
        {
            SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
            rijn.GenerateKey();
            rijn.GenerateIV();
            Boolean b1 = RegistryWrite("Software\\MyApp", "IV", Reverse(Convert.ToBase64String(rijn.IV)));
            Boolean b2 = RegistryWrite("Software\\MyApp", "Key", Reverse(Convert.ToBase64String(rijn.Key)));
            Boolean b3 = RegistryWrite("Software\\MyApp", "DSN", Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Reverse(txtDSN))));
            Boolean b4 = RegistryWrite("Software\\MyApp", "Server", Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Reverse(txtServer))));
            Boolean b5 = RegistryWrite("Software\\MyApp", "Database", Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Reverse(txtDatabase))));
            Boolean b6 = RegistryWrite("Software\\MyApp", "User", EncryptString(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Reverse(txtUser))),rijn.IV,rijn.Key));
            Boolean b7 = RegistryWrite("Software\\MyApp", "Password", EncryptString(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Reverse(txtPassword))), rijn.IV, rijn.Key));
            Boolean b8 = RegistryWrite("Software\\MyApp", "Trusted", Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Reverse(trusted ? "1" : "0"))));

            if (b1 && b2 && b3 && b4 & b5 & b6 & b7 & b8)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


  private bool RegistryWrite(string subKey, string KeyName, object Value)
        {
            try
            {
                RegistryKey rk = Registry.LocalMachine;
                RegistryKey sk1 = rk.CreateSubKey(subKey);
                sk1.SetValue(KeyName.ToUpper(), Value);
                return true;
            }
            catch (Exception e)
            {
            }
            return false;
        }

这些方法包含在一个公共类中,它是我在 ASP.NET 网页中安装的 dll 的一部分。当从 Windows 应用程序调用该方法进行测试时,这些方法成功写入注册表,但是当从网站后面的代码调用该方法时,尽管返回 true,但它无法写入创建文件夹和键。我怎样才能解决这个问题?.dll 的框架是 .Net 2.0,Web 应用程序是 4.0。感谢您的帮助。

4

0 回答 0