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

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>

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

  

ASPNET_REGIIS -pef “MyCustomSection”   C:\的Inetpub \ wwwroot的\ MyWebsite -prov   DataProtectionConfigurationProvider

我得到一个错误:

  

加密配置节...一个   发生错误创建   对于配置节处理程序   MyCustomSection:未能加载文件   或程序集“MyAssembly程序”或一种其   依赖。系统无法找到   指定的文件。   (C:\的Inetpub \ wwwroot的\ MyWebsite \的web.config   第5行)

我与/尝试没有配置的提供者。有/无节组。有/无已经开始用手之前的网站。我试着暂时把我的组件在GAC进行注册。我也试过我的log4net的部分只是尝试的东西,是不是我的,没有运气。我已经运行的命令提示符管理员。有任何想法吗?或者可以ASPNET_REGIIS只是没有被用于自定义板块?

MSDN 后最后一个射门被改变我的处理程序自ConfigurationSection继承,而不是实现IConfigurationSectionHandler因为它是在2.0技术弃用(希望是关于ASPNET_REGIIS版本的东西)。没有运气任

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

有帮助吗?

解决方案

aspnet_regiis必须能够装配结合。正常的.NET中的绑定规则。

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

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

我然后复制定义自定义配置节到aspnet_regiis_bin的组件,使得aspnet_regiis能够找到它们。

此过程不需要进行强命名或在GAC程序集,但要求在框架目录瞎搞。

其他提示

我使用一种变通方法,其中我即暂时注释掉configSections元素的内容:

<configSection>
    <!--
    <section name="CustomSection" type="" />
    -->
</configSection>

可以然后运行使用aspnet_regiis -pef照常进行加密。这种运行后只是取消注释部分,您的网站是准备运行。

这是一个总的黑客,但我不知道有另一种方式来做到这一点没有强烈的命名,定义您的自定义部分的组装和GACifying它(尽管你提到,没有工作,要么和我不能确定为什么它不会)。由于ASPNET_REGIIS <驱动器>运行:\ WINDOWS \ Microsoft.Net \框架\ <版本>文件夹(在WinXP),你可以复制定义你的配置节到相关框架\ <版本>文件夹中的DLL,然后将其应工作。

有关的记录,我结束了一个小保养页为我做到这一点。

var currentConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
// Unprotect
ConfigurationSection section = currentConfig.GetSection("MyCustomSection");
if (section.SectionInformation.IsProtected)
{
   section.SectionInformation.UnprotectSection();
   currentConfig.Save();
}

// Protect
if (!section.SectionInformation.IsProtected)
{
     section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
     currentConfig.Save();
}

注意事项:你的过程将需要的配置文件的写权限被修改。你会想一些方法来授权谁可以运行此。你会一般重新启动该网站,当你保存。

这被示出为正确答案是正确的。我想添加注释,但不能因为这一个太长的注释(样本配置项)。

节名应该使用组件的全名。运行时组件资格不与ASPNET_REGIIS.EXE工作。

此WORKS:

<configSections>
  <section name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=9c844884b2afcb9e" />
</configSections>

但是,这不工作:

<configSections>
  <section name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security" />
</configSections>

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Security" fullName="Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=9c844884b2afcb9e" />
    </assemblyBinding>
</runtime>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top