加密web.config的自定义部分 [英] Encrypting custom sections of a web.config

查看:270
本文介绍了加密web.config的自定义部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用文章创建灵活配置节处理程序来创建灵活配置



我也看到这篇文章标题为在OdeToCode博客上加密自定义配置部分,了解如何加密web.config文件的部分。



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

 <?xmlversion =1.0encoding =utf-8?> 
< configuration>
< configSections>
< sectionname =StyleSheetSettings_1
type =FifteenSeconds.Core.BasicConfigurator/>
< / configSections>
< StyleSheetSettings_1>
< StyleSheets>
< Style SheetName =PageHref =Styles / Page.cssMedia =screen/>
< StyleSheetName =CustomHref =Styles / Custom.cssMedia =screen/>
< StyleSheetName =PrintHref =/ Lib / Styles / Print.cssMedia =print/>
< / StyleSheets>
< / StyleSheetSettings_1>
< / configuration>

我试图使用以下代码使用类似以下命令行代码加密代码。 / p>

  aspnet_regiis.exe -pefStyleSheetSettings_1C:\Test\ 

我收到以下错误


无法加载类型
FifteenSeconds.Core.BasicConfigurator'
从程序集System.Web,
版本= 4.0.0.0,文化=中立,
PublicKeyToken = b03f5f7f11d50a3a'。

$ b $

解决方案

这里有另一种解决方法对于此问题(位于 http://www.dotnetnoob.com/2013/ 01 / how-to-encrypt-custom-configuration.html )。在运行aspnet_regiis命令之前,注释掉configSections元素(/ configuration / configSections)下的自定义节的section元素,并且自定义节应加密。

 < configSections> 
<! - < section name =myCustomSectiontype =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版本4.0.30319.17929
管理实用程序在本地机器上安装和卸载ASP.NET
版权所有(C)Microsoft Corporation。保留所有权利。
加密配置部分。 ..
成功!


I used the article Creating a Flexible Configuration Section Handler to create a Flexible Configuration Section Handler in my application.

I also saw this article entitled Encrypting Custom Configuration Sections on the OdeToCode blog, on how to encrypt portions of a web.config file.

From the first article, we have this web.config code.

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

I tried to use the following code to encrypt the code using something like the following command line code.

 aspnet_regiis.exe -pef  "StyleSheetSettings_1" C:\Test\

I am getting the following error

Could not load type FifteenSeconds.Core.BasicConfigurator' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Any help would be appreciated.

解决方案

Here's another workaround for this issue (found at http://www.dotnetnoob.com/2013/01/how-to-encrypt-custom-configuration.html). Comment out the section element for the custom section under the configSections element (/configuration/configSections) before running the aspnet_regiis command and the custom section should get encrypted.

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

这篇关于加密web.config的自定义部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆