これはSQL Server 接続のパスワードをハッシュとしてキャッシュする のフォローアップです。
http://www.codeproject.com/Articles/15392/Implementing-Protected-Configuration-With-Windowsでは、ローカル Windows アプリケーションが保護された構成を使用する方法について説明しています。ただし、アプリケーションを実行するように設計されている環境に基づいて、インストーラーは望ましくありません。
私は以下を実行しようとしました:
object settings = ConfigurationManager.GetSection("userSettings/MyApp.Properties.Settings");
SectionInformation info = ((ConfigurationSection)settings).SectionInformation;
if (!info.IsProtected)
info.ProtectSection("DPAPIProtection");
私のWPFアプリケーションではいくつかの異なる時点で、しかし私がそうするたびに、VerifyIsEditableの.NETのSectionInformation.csからこの例外を受け取ります:
if (IsLocked) {
throw new InvalidOperationException(SR.GetString(SR.Config_cannot_edit_configurationsection_when_locked));
そう。(a) 構成がロードされてロックされる前に実行する方法ProtectSection()
、または (b) を呼び出した後のアプリケーションの最後にSettings.Default.Save()
、構成をフラッシュし、閉じてロックを解除してから呼び出す方法はありますProtectSection()
か?