ASP.NET 2.0 中加密Web.config中的项目
2006-01-28 22:16
573 查看
ASP.NET 2.0给我们带来不少安全性方面的改进,让我们的Web应用越来越安全。在ASP.NET项目中我们的数据库链接字符串都大多写在了Web.config的文件中,数据库用户密码一览无余,这样显然是不安全的。我们可能自己动手写了一些加密解密算法来加密,现在好了在ASP.NET 2.0中系统为我们提供了这样的功能。
<connectionStrings>
<add name="Pubs" connectionString="Server=localhost;Integrated Security=True;Database=Pubs"
providerName="System.Data.SqlClient" />
<add name="Northwind" connectionString="Server=localhost;Integrated Security=True;Database=Northwind"
providerName="System.Data.SqlClient" />
</connectionStrings>
我们如果有操作Web Server的权限,我们可以不用Coding来加密,直接使用命令行
aspnet_regiis -pe "connectionStrings" -app "/SampleApplication"
如果我们没法操作Web Server的话只好采用代码方法
Configuration config = Configuration.GetWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.Sections["connectionStrings"];
section.ProtectSection ("DataProtectionConfigurationProvider");
config.Update();
加密后我们看到
<connectionStrings>
<EncryptedData>
<CipherData>
<CipherValue>AQAAANCMndjHoAw...</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
<connectionStrings>
<add name="Pubs" connectionString="Server=localhost;Integrated Security=True;Database=Pubs"
providerName="System.Data.SqlClient" />
<add name="Northwind" connectionString="Server=localhost;Integrated Security=True;Database=Northwind"
providerName="System.Data.SqlClient" />
</connectionStrings>
我们如果有操作Web Server的权限,我们可以不用Coding来加密,直接使用命令行
aspnet_regiis -pe "connectionStrings" -app "/SampleApplication"
如果我们没法操作Web Server的话只好采用代码方法
Configuration config = Configuration.GetWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.Sections["connectionStrings"];
section.ProtectSection ("DataProtectionConfigurationProvider");
config.Update();
加密后我们看到
<connectionStrings>
<EncryptedData>
<CipherData>
<CipherValue>AQAAANCMndjHoAw...</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
相关文章推荐
- ASP.NET 2.0 中加密Web.config中的项目
- Asp.Net 2.0加密Web.config配置文件
- ASP.NET 2.0加密Web.config 配置文件
- asp.net 2.0中加密web.config /App.config
- asp.net 2.0 中加密web.config 文件中的配置节
- ASP.NET 2.0加密Web.config 配置文件
- ASP.NET 2.0加密解密Web.config配置文件
- ASP.NET 2.0加密Web.config 配置文件
- ASP.NET 2.0加密Web.config 配置文件
- ASP.NET 2.0加密Web.config 配置文件
- asp.net 2.0 中加密web.config 文件中的配置节
- ASP.NET 2.0加密Web.config 配置文件
- ASP.NET 2.0加密Web.config 配置文件 (终极版)
- asp.net 2.0中加密web.config
- ASP.NET 2.0加密Web.config 配置文件
- asp.net 2.0中加密web.config
- ASP.NET 2.0加密Web.config 配置文件
- ASP.NET 2.0加密Web.config 配置文件
- ASP.NET 2.0加密Web.config 配置文件
- [导入]ASP.NET 2.0加密Web.config 配置文件