28

私はカスタム設定セクションを持つWebアプリケーションを持っています。そのセクションには、私が暗号化するような情報が含まれています(自分ではなくASPNet_RegIISを使用したいと考えていました)。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

私はエラーを取得する:

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は、IConfigurationSectionHandlerを実装するのではなく、ConfigurationSectionから継承するようにハンドラーを変更していました。技術的には2.0で廃止されていました(aspnet_regiisバージョンに関する)。そこにも運はない。

私にはどんなアイデアも教えてください。ありがとう!

+0

私は同じ問題を抱えています。私は、下の答えでgacやハックのアセンブリを入れないでこれを動作させる方法があるとは思わない? –

+0

私はそれをしつこに疲れていたので、私はちょうどガックの中にアセンブリを一時的に入れて行った。 –

答えて

29

aspnet_regiisは、アセンブリをバインドできる必要があります。通常の.netバインディングルールが適用されます。

私は aspnet_regiis.exeと同じディレクトリと、このような民間のパスとして aspnet_regiis_binaspnet_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がそれらを見つけることができるようにaspnet_regiis_binに。

この手順では、アセンブリの名前を厳密に指定する必要はありませんが、GACではアセンブリのフレームワークディレクトリを煩わせる必要があります。

+0

http://stackoverflow.com/questions/786661/using-aspnet-regiis-to-encrypt-custom-configuration-section-can-you-do-itにお答えください。 – Lijo

+3

天才!注:Framework64フォルダではなく、C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \フォルダに入れてください。 –

4

これはトータルのハックですが、あなたのカスタムセクションを定義してGACifyingを強く指定しなければ、別の方法があるとは思えません。なぜそれができないのかわかりません)。 aspnet_regiisは<ドライブ>:\ Windows \ Microsoft.Net \ Framework \ <バージョン>フォルダ(WinXP)で実行されるため、設定セクションを定義するDLLを関連するFramework \ <バージョン>フォルダにコピーしてからうまくいくはずです。

+1

私はそれをGACに移したときに強い名前で署名されました。私はまた、configuration/section.typeにバージョン/文化/公開鍵を含めるようにしました。あなたの解決策は私を通り抜けましたが、ありがとうございました。 他に誰かがこれに遭遇した場合、私は答えがフレームワークフォルダにdllを移動してしまったので、aspnet_regiisを管理者(Windows Server 2007)として実行しています。 –

+0

私はGACから登録するようになった。私はGACに登録しようとしなかったし、同時にタイプの長いフォームを使用することはなかった(私は別々の時間に両方を行ったが)。それについて考えた後、アセンブリがGACに存在することが要求されるのは理にかなっています。再度、感謝します。 –

+0

私もこれにいくつか問題がありました。 –

2

正しい答えが正しいです。私はコメントを追加したかったのですが、これはコメントの長さが長すぎるため(サンプル設定エントリ)できませんでした。

セクション名には、アセンブリのフルネームを使用する必要があります。 aspnet_regiis.exeでは、ランタイムアセンブリの修飾は機能しません。

この作品:

<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> 
13

私はtemporarly configSections要素の内容をコメントアウトすることにより回避策を使用しています:

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

その後、いつものようにaspnet_regiis -pefを使って暗号化を実行できます。これが実行された後、セクションのコメントを外して、サイトを実行する準備が整いました。

+0

ありがとうございます。あなたの提案を使用してプロセスを自動化することができました(Powershellがセクション名をコメントアウトしてからaspnet_regiisが実行され、Powershellを介してコメントが再度削除されます)。 –

3

記録のために、私はこれを行うための少しのメンテナンスページで終わった。

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(); 
} 

注意:プロセスには、変更される設定ファイルへの書き込みアクセス権が必要です。誰がこれを実行できるのかを承認する方法が必要です。保存するとgenerallyウェブサイトを再起動します。

関連する問題