国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

淺談ASP.NET2.0中配置文件的加密與解密_.Net教程

2024-07-10 12:50:57
字體:
供稿:網(wǎng)友

推薦:ASP.NET遍歷配置文件的連接字符串
在ASP.NET 2.0中,提供了更方便的配置文件訪問的類,具體可以到System.Configuration名稱空間下進行查看。本文提供一種在開發(fā)過程中常用的得到數(shù)據(jù)庫字符串的方法,為方便使用,寫成一個方法進行調(diào)用: 以下為引用的內(nèi)容: public string GetConnectionStrin

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

加密操作如下:

以下為引用的內(nèi)容:

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();
}
}

解密操作如下:

以下為引用的內(nèi)容:


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();
}
}


實踐:

加密前的配置文件:

以下為引用的內(nèi)容:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="name" value="shy520" />
<add key="address" value="VeVb" />
</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>

分享:探討.Net整合其他平臺
整合分布式應(yīng)用程序經(jīng)常是一件非常困難并且錯綜復雜的任務(wù),即使是最富有經(jīng)驗的開發(fā)者也可能會覺得頭疼。當應(yīng)用程序在不同的操作系統(tǒng)以及涉及不同的程序平臺時,這個集成問題變得尤其復雜。雖然說,Web服務(wù)承諾可以減輕程序員完成集成任務(wù)的困難程度,但是也

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳春市| 澄江县| 邓州市| 黎平县| 中牟县| 民权县| 象山县| 阳曲县| 通化市| 辉县市| 玉溪市| 塔城市| 安塞县| 潞西市| 林州市| 海盐县| 静乐县| 临潭县| 大理市| 南乐县| 黄龙县| 任丘市| 石狮市| 宝山区| 汾阳市| 丰都县| 开阳县| 子长县| 林周县| 民勤县| 绿春县| 瓮安县| 万源市| 新乡市| 龙泉市| 库尔勒市| 灵川县| 南充市| 紫云| 襄垣县| 油尖旺区|