使用ASPNET_REGIIS加密自定义配置节 - 你能做到吗? [英] Using ASPNet_Regiis to encrypt custom configuration section - can you do it?

查看:195
本文介绍了使用ASPNET_REGIIS加密自定义配置节 - 你能做到吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义配置节的Web应用程序。这部分包含的信息I'ld要加密(希望使用ASPNET_REGIIS,而不是自己动手)。

I have a web application with a custom configuration section. That section contains information I'ld like to encrypt (was hoping to use ASPNet_RegIIS rather than do it myself).

Web.Config中:

Web.Config:

<?xml version="1.0"?>

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
      <configSections>
          <section name="MyCustomSection" 
                   type="MyNamespace.MyCustomSectionHandler, MyAssembly"/>
    </configSections>
<configProtectedData>
    <providers>
      <clear />
      <add name="DataProtectionConfigurationProvider"
           type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,
                   Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
                   processorArchitecture=MSIL"
           keyContainerName="MyKeyContainer"
           useMachineContainer="true" />
    </providers>
  </configProtectedData>
    <MyCustomSection>
       <blah name="blah1">
          <blahChild name="blah1Child1" />
       </blah>
    </MyCustomSection>

配置处理程序试图加密前的伟大工程。当我尝试将它与加密:

The configuration handler works great before trying to encrypt it. When I try to encrypt it with:

为aspnet_regiis -pefMyCustomSection
  C:\\的Inetpub \\ wwwroot的\\ MyWebsite -prov
  DataProtectionConfigurationProvider

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

我得到一个错误:

加密配置节...一个
  错误发生创建
  配置节处理程序
  MyCustomSection:无法加载文件
  或程序集MyAssembly程序或之一其
  依赖。系统不能找到
  指定的文件。
  (C:\\的Inetpub \\ wwwroot的\\ MyWebsite \\ web.config中
  5号线)

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只是不能用于自定义的部分?

I have tried with/without the provider configured. With/without section groups. With/Without having started the website before hand. I've tried temporarily putting my assembly in the GAC for the registration. I also tried my log4net section just to try something that wasn't mine, with no luck. I've run the command prompt as Administrator. Any ideas? Or can ASPNet_RegIIS just not be used for custom sections?

最后一个镜头<一个href=\"http://msdn.microsoft.com/en-us/library/system.configuration.iconfigurationsectionhandler.aspx\">MSDN正在改变我的处理程序,以自ConfigurationSection继承,而不是实现IConfigurationSectionHandler,因为它在技术上是德$ P $ 2.0 pcated(希望是关于版本aspnet_regiis的东西)。没有运气无论是。

One final shot after viewing MSDN was changing my handler to inherit from ConfigurationSection rather than implementing IConfigurationSectionHandler since it was technically deprecated in 2.0 (hoping it was something regarding aspnet_regiis version). No luck there either.

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

Any ideas let me know. Thanks!

推荐答案

为aspnet_regiis 必须能够装配约束。正常的.NET中的绑定规则。

aspnet_regiis must be able to bind the assembly. The normal .net binding rules apply.

我解决这个问题通过创建一个名为 aspnet_regiis_bin 在同一目录的目录 ASPNET_REGIIS.EXE aspnet_regiis.exe.config 文件aspnet_regiis_bin 为这样的私人路径:

I get around this by creating directory called aspnet_regiis_bin in the same directory as aspnet_regiis.exe and an aspnet_regiis.exe.config file with aspnet_regiis_bin as a private path like this:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="aspnet_regiis_bin"/>
      </assemblyBinding>
   </runtime>
</configuration>

我然后复制定义自定义配置节到 aspnet_regiis_bin 的组件,使为aspnet_regiis 可以找到他们。

I then copy the assemblies that define the custom configuration sections into aspnet_regiis_bin so that aspnet_regiis can find them.

这个过程不需要被强命名,或在GAC中集,但确实需要在框架目录乱搞。

This procedure doesn't require the assemblies to be strong named or in the GAC but does require messing around in the framework directories.

这篇关于使用ASPNET_REGIIS加密自定义配置节 - 你能做到吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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