加密web.config的自定义部分

Bra*_*fur 12 asp.net configuration web-config

我使用文章创建灵活配置节处理程序在我的应用程序中创建灵活配置节处理程序.

我还在OdeToCode博客上看到了题为加密自定义配置部分的文章,介绍了如何加密web.config文件的各个部分.

从第一篇文章中,我们有了这个web.config代码.

<?xmlversion="1.0"encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionname="StyleSheetSettings_1"    
            type="FifteenSeconds.Core.BasicConfigurator"/>
    </configSections>
    <StyleSheetSettings_1>
        <StyleSheets>
            <Style SheetName="Page"Href="Styles/Page.css"Media="screen"/>
            <StyleSheetName="Custom"Href="Styles/Custom.css"Media="screen"/>
            <StyleSheetName="Print"Href="/Lib/Styles/Print.css"Media="print"/>
        </StyleSheets>      
    </StyleSheetSettings_1>
 </configuration>
Run Code Online (Sandbox Code Playgroud)

我尝试使用以下代码使用类似以下命令行代码的方式加密代码.

 aspnet_regiis.exe -pef  "StyleSheetSettings_1" C:\Test\
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

不能"从组件 '的System.Web,版本= 4.0.0.0,文化=中性公钥= b03f5f7f11d50a3a' 加载类型FifteenSeconds.Core.BasicConfigurator.

任何帮助,将不胜感激.

dni*_*els 19

以下是此问题的另一种解决方法(可在http://www.dotnetnoob.com/2013/01/how-to-encrypt-custom-configuration.html找到).在运行aspnet_regiis命令之前注释掉configSections元素(/ configuration/configSections)下自定义部分的section元素,并且自定义部分应该加密.

<configSections>
    <!--<section name="myCustomSection" type="My.Product.CustomSection, My.Product.Assembly/>-->
</configSections>


c:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -pef myCustomSection C:\path\to\app
Microsoft (R) ASP.NET RegIIS version 4.0.30319.17929
Administration utility to install and uninstall ASP.NET on the local machine.
Copyright (C) Microsoft Corporation.  All rights reserved.
Encrypting configuration section...
Succeeded!
Run Code Online (Sandbox Code Playgroud)

  • 3 年过去了,这个错误仍然没有修复。该死的。 (2认同)

Ada*_*dam 8

唯一已知的解决方案是可怕的黑客攻击.将程序集(和所有依赖项)复制到相关的.NET框架目录(aspnet_regiis.exe所在的目录).


Con*_*rix 0

尝试更改类型以包含程序集名称

type="FifteenSeconds.Core.BasicConfigurator, MyWebApplication"
Run Code Online (Sandbox Code Playgroud)

这假设 BasicConfiguration 位于您的 Web 应用程序中

  • 添加程序集名称 type="FifteenSeconds.Core.BasicConfigurator,FifteenSeconds.Core" 后,我仍然收到以下错误。正在加密配置节...为 StyleSheetSettings_1 创建配置节处理程序时发生错误:无法加载文件或程序集“FifteenSeconds.Core”或其依赖项之一。该系统找不到指定的文件。 (2认同)