ASP.NET WEB.CONFIG敏感信息加密学习
今天,看到PETSHOP4.0里的WEB.CONFIG对数据库连接字符串加密,所以特意学习并记录下来。
.net 提供了 System.Configuration.RsaProtectedConfigurationProvider 。
首先配置WEB.CONFIG
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configProtectedData>
<providers>
<clear />
<add name="KeyProvider" type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" keyContainerName="Key" useMachineContainer="true" />
</providers>
</configProtectedData>
<connectionStrings>
<add name="SQL_Northwind" connectionString="Data Source=localhost;Initial Catalog=Northwind;User ID=sa;Password=sa;" />
</connectionStrings>
</configuration>
asp.net 提供了命令行的方式,对其加密,这里我也没有具体实例,就不讲啦。
我还是按照程序的方式,新建一个页面
执行下面的方法:
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection("connectionStrings");
if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("KeyProvider");
config.Save();
}
方法执行后,WEB.CONFIG 文件应该有类似以下的代码出现:
<connectionStrings configProtectionProvider="KeyProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<Encrypt
相关文档:
首页:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head ......
原帖地址:http://www.wangchao.net.cn/bbsdetail_572426.html
简介
有许多聪明的办法可以解决HTTP协议的无状态问题,例如对每个请求重复发送应用程序数据包、使用HTTP认证机制来将请求映射到特定的用户、使用Cookie来存储一系列请求的状态等。在ASP.net技术中提供了 ......
ASP.NET C# 生成静态页面简单方法
//源码是替换掉模板中的特征字符
string mbPath = Server.MapPath("template.html");
Encoding cod ......
此处提供的代码用来实现当asp.net页面中的某个Button被点击后disable掉该页面中所有的Button,从而防止提交延时导致的多次提交。基于之前的onceclickbutton脚本.
//ASP.NET中防止页面多次提交的代码:javascript< script language="javascript"> < !-- function disableOtherSubmit() {
var o ......
asp.net和ajax未捕获异常处理机制
这里的异常处理主要是指开发人员在业务代码中未捕获的异常。未捕获异常处理的目的:
1:在应用程序域级别对异常类型进行处理;
2:在处理的基础上,可以将错误信息记录日志;
3:以友好的方式提示最终用 ......