网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.自动处理过长字符串显示的Web控件.
.ASPX页Web服务调用性能优化.
.慎用url重写 .
.在 IIS 中配置 SQL XML 支持.
.ASP.NET 崩溃-SiteMap中疯狂的循.
.存储过程的分析.
.asp.net 水晶报表-主从表关联问题.
.ASP.NET查询ACCESS数据库的内容并.
.ASP.NET2.0 WebRource,开发微调按.
.asp.net如何生成图片验证码(简单) .
.ASP.NET操作IIS中的虚拟目录.
.asp.net自动执行任务-解决应用池.
.UpdatePanel与UrlRewrite.
.asp.net 2.0中一次性更新所有GRI.
.用JavaScript打造搜索工具栏.
.ASP.NET 2.0 多文件上传小经验 .
.小tips:asp.net 2.0中在gridview.
.解决错误:sql_variant is incom.
.Asp.net 2.0 关于Header/title/M.
.利用Treeview实现树形列表.

ASP.NET2.0中配置文件的加密与解密

发表日期:2006-6-26


首先添加引用: using System.Web.Configuration;

加密操作如下:
private void ProtectSection(string sectionName, string provider)
    {
        Configuration config =
            WebConfigurationManager.
                OpenWebConfiguration(Request.ApplicationPath);

        ConfigurationSection section = config.GetSection(sectionName);

        if (section != null && !section.SectionInformation.IsProtected)
        {
            section.SectionInformation.ProtectSection(provider);
            config.Save();
        }
    }

解密操作如下:
 private void UnProtectSection(string sectionName)
    {
        Configuration config =
            WebConfigurationManager.
                OpenWebConfiguration(Request.ApplicationPath);

        ConfigurationSection section = config.GetSection(sectionName);

        if (section != null && section.SectionInformation.IsProtected)
        {
            section.SectionInformation.UnprotectSection();
            config.Save();
        }
    }
实践:
加密前的配置文件:
<?xml version="1.0"?>
<configuration>
    <appSettings>
  <add key="name" value="shy520" />
  <add key="address" value="cnblogs" />
 </appSettings>
    <system.web>
        <compilation debug="true"/>
  </system.web>
</configuration>
加密后的配置文件:
<?xml version="1.0"?>
<configuration>
    <appSettings configProtectionProvider="DataProtectionConfigurationProvider">
  <EncryptedData>
   <CipherData>
    <CipherValue>
      AQAAANCMnd8BFdERjHoAwE/Cl+s
      BAAAABi1ATlNkEUGEf0XyWGL2Xg
      QAAAACAAAAAAADZgAAqAAAABAAA
      ABIhxMWlazAntwIIpST1CDXAAAA
      AASAAACgAAAAEAAAAPz/YKYx07c
      b+h4fqdr4fkLgAAAAX1Ieyc+WSx
      AfsDW1vn2C/fXsG2TAnYeUgaCov
      8e3nGFTHHsH91gLiqKregFPYzGR
      vW1xrez/3VwOmJI9eS7EFKrcXej
      NnHL66kg2iNRk3ntLNZlZtTs3cZ
      9w63u47VKAjs6miWsGBz2GntL/9
      UGHLELigrJcr3YJ+lsjOscExQnv
      HGvA48EfxpD+tEiFBtgXeHsFkQX
      cqGySshx16vCt2GUNUC3ZmEAhBh
      UsAFkPIYqelYHd4+m9a/xPe2tqw
      GIbla1wbW2NDEfrzJPwnkfmpNqR
      hXijKImipwXbDVYy6o0UAAAAs8D
      suYNOhJ7qAjJa2c/4eUC7sks=
      </CipherValue>
   </CipherData>
  </EncryptedData>
 </appSettings>
    <system.web>
        <compilation debug="true"/>
  </system.web>
</configuration>

上一篇:ASP.Net2.0中自定义控件在page中的注册 人气:6565
下一篇:ASP.NET 2.0站点地图搭建网站导航结构 人气:6362
浏览全部ASP.NET的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐