【问题标题】:Provider not found when encrypting web.config加密 web.config 时找不到提供程序
【发布时间】:2013-04-19 03:08:59
【问题描述】:

我正在尝试加密 web.config 文件中的自定义部分。
当我到达调用 ProtectSection() 的行时,我收到一个异常,说找不到提供程序。

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);  
ConfigurationSection section = config.GetSection("MySection");  
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); 

我也尝试使用 RSA 并得到同样的错误。
运行 aspnet_regiis.exe 有效,但我需要以编程方式执行此操作。我错过了什么?

谢谢。

【问题讨论】:

    标签: c# asp.net encryption web-config


    【解决方案1】:

    您使用 `DataProtectionConfigurationProvider' 是正确的(see here for the provider names - dpapi 的提供者名称中没有 dpapi - 但 rsa 的提供者 ) ,但是,您的问题是 您不能在名为“MySection”的部分上运行 iisreg - 它必须是某些部分。

    消息的意思是没有可用于该特定部分的提供程序。

    但是,要测试您的代码,您可以尝试使用"AppSettings""connectionStrings""system.net/mailSettings/smtp"。 - 所有这些都适用于 aspnet_regiis.exe。

    请参阅other Stack Exchange thread,了解如何加密自定义部分。

    【讨论】:

      【解决方案2】:

      如果您尝试向我们提供 Windows 数据保护提供程序,则不应将传递给 ProtectSetion 的参数说为 "DpapiProtectedConfigurationProvider"

      对于 RSA,它应该是 "RsaProtectedConfigurationProvider",这是默认和首选选项

      【讨论】:

      • 我试了一下,但仍然遇到同样的错误:无法加密 MySection。找不到保护提供程序“DpapiProtectedConfigurationProvider”。无法加密 MySection。未找到保护提供程序“RsaProtectedConfigurationProvider”。
      • 不,它不应该被称为“DpapiProtectedConfigurationProvider”——它可能是提供者,但它不是您用于该提供者的字符串。 MSN:“一个名为 DataProtectionConfigurationProvider 的 DPAPIProtectedConfigurationProvider 实例。”
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 2013-06-25
      • 1970-01-01
      • 2023-01-31
      • 2021-12-15
      相关资源
      最近更新 更多