SMTPサーバー&ログイン情報が保護されるように、web.configファイルのelmahセクションを暗号化するにはどうすればよいですか?web.configファイルのelmahセクションの暗号化
私は、接続文字列、appSettings、およびその他のセクションを暗号化する方法を学びました。コードまたはaspnet_regiis.exeを使用します。
ただし、セクションを暗号化しようとすると、セクションが見つからないことがわかります。
暗号化の秘訣はありますか?
おかげで、+ M
SMTPサーバー&ログイン情報が保護されるように、web.configファイルのelmahセクションを暗号化するにはどうすればよいですか?web.configファイルのelmahセクションの暗号化
私は、接続文字列、appSettings、およびその他のセクションを暗号化する方法を学びました。コードまたはaspnet_regiis.exeを使用します。
ただし、セクションを暗号化しようとすると、セクションが見つからないことがわかります。
暗号化の秘訣はありますか?
おかげで、+ M
上記の情報は正しいです(あなたは「errorMail」または特定のターゲットにする必要があることelmahグループのサブセクション)。しかし、ソリューションは必要以上に多くのコードです...
"elmah/errorMail"だけを使用した、よりクリーンなソリューションです。ソリューション:
string section = "elmah/errorMail";
Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);
// Let's work with the section
ConfigurationSection configsection = config.GetSection(section);
if (configsection != null)
// Only encrypt the section if it is not already protected
if (!configsection.SectionInformation.IsProtected)
{
// Encrypt the <connectionStrings> section using the
// DataProtectionConfigurationProvider provider
configsection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
config.Save();
}
は、私が使用します。aspnet_regiisを試みたが、トラブルセクションのパスを指定していました。コードベースのアプローチに切り替えると、Sectionセクションが列挙され、セクションのみが暗号化され、ElmahはSectionGroupなので、私はelmah SectionGroupの下でerrorMailセクションを暗号化する必要があることを学びました。私は昨日より少しだけ知っています。
それはglobal.asax.csからのラインの下の他の誰かに便利だ場合、これは、スニペットです:
private static void ToggleWebEncrypt(bool Encrypt)
{
// Open the Web.config file.
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
//.... (protect connection strings, etc)
ConfigurationSectionGroup gpElmah = config.GetSectionGroup("elmah");
if (gpElmah != null)
{
ConfigurationSection csElmah = gpElmah.Sections.Get("errorMail");
ProtectSection(encrypted, csElmah);
}
//.... other stuff
config.Save();
}
private static void ProtectSection(bool encrypted, ConfigurationSection sec)
{
if (sec == null)
return;
if (sec.SectionInformation.IsProtected && !encrypted)
sec.SectionInformation.UnprotectSection();
if (!sec.SectionInformation.IsProtected && encrypted)
sec.SectionInformation.ProtectSection("CustomProvider");
}