asp.net – 使用ASPNet_Regiis加密自定义配置部分 – 你能做到吗?

前端之家收集整理的这篇文章主要介绍了asp.net – 使用ASPNet_Regiis加密自定义配置部分 – 你能做到吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个Web应用程序与自定义配置部分。该部分包含我想加密的信息(希望使用ASPNet_RegIIS,而不是自己做的)。

Web.Config:

  1. <?xml version="1.0"?>
  2.  
  3. <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  4. <configSections>
  5. <section name="MyCustomSection"
  6. type="MyNamespace.MyCustomSectionHandler,MyAssembly"/>
  7. </configSections>
  8. <configProtectedData>
  9. <providers>
  10. <clear />
  11. <add name="DataProtectionConfigurationProvider"
  12. type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a,processorArchitecture=MSIL"
  13. keyContainerName="MyKeyContainer"
  14. useMachineContainer="true" />
  15. </providers>
  16. </configProtectedData>
  17. <MyCustomSection>
  18. <blah name="blah1">
  19. <blahChild name="blah1Child1" />
  20. </blah>
  21. </MyCustomSection>

配置处理程序在尝试加密之前工作得很好。当我尝试加密它与:

aspnet_regiis -pef “MyCustomSection”
c:\inetpub\wwwroot\MyWebsite -prov
DataProtectionConfigurationProvider

我得到一个错误

Encrypting configuration section… An
error occurred creating the
configuration section handler for
MyCustomSection: Could not load file
or assembly ‘MyAssembly’ or one of its
dependencies. The system cannot find
the file specified.
(c:\inetpub\wwwroot\MyWebsite\web.config
line 5)

我已经尝试与/没有配置的提供程序。带/不带节组。有/没有手前开始的网站。我试过暂时把我的程序集在GAC中注册。我也试过我的log4net部分只是为了尝试不是我的东西,没有运气。我以管理员身份运行命令提示符。有任何想法吗?或者可以ASPNet_RegIIS只是不是用于自定义部分?

在查看MSDN后的最后一个镜头是改变我的处理程序继承自ConfigurationSection,而不是实现IConfigurationSectionHandler,因为它在技术上已被弃用2.0(希望它是关于aspnet_regiis版本)。也没有运气。

任何想法让我知道。谢谢!

解决方法

aspnet_regiis必须能够绑定程序集。正常的.net绑定规则适用。

我通过在与aspnet_regiis.exe相同的目录中创建名为aspnet_regiis_bin的目录和aspnet_regiis.exe.config文件(aspnet_regiis_bin作为私有路径)来解决此问题:

  1. <configuration>
  2. <runtime>
  3. <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  4. <probing privatePath="aspnet_regiis_bin"/>
  5. </assemblyBinding>
  6. </runtime>
  7. </configuration>

然后,我将定义自定义配置节的程序集复制到aspnet_regiis_bin中,以便aspnet_regiis可以找到它们。

此过程不需要强制命名或在GAC中的程序集,但确实需要在框架目录中搞乱。

猜你在找的asp.Net相关文章