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
相关文档:
ASP.Net邮件发送类
本文转自:http://www.pcstu.com/program/Asp_net/sl/20070706/52523.html
说明:本文没有测试,但看起来似乎不能用于发送附件,如要发送附件,可参考:http://blog.csdn.net/lff642/archive/2008/07/15/2654346.aspx
using System;
using System.Text;
using System.IO;
using System.Net;
using ......
使用DataRelation类创建关系并利用父/子关系读取数据示例
void Page_Load(object sender, System.EventArgs e)
{
// 连接字符串和 SQL 语句
string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];
......
此处提供的代码用来实现当asp.net页面中的某个Button被点击后disable掉该页面中所有的Button,从而防止提交延时导致的多次提交。基于之前的onceclickbutton脚本.
//ASP.NET中防止页面多次提交的代码:javascript< script language="javascript"> < !-- function disableOtherSubmit() {
var o ......
ASP.NET生成随机密码
在开发需要用户注册后才能使用提供的各项功能的应用程序时,在新用户提交注册信息后,较常见的做法是由程序生成随机密码,然后发送密码到用户注册时填写的电子信箱,用户再用收到的密码来激活其帐户。
实现ASP.NET生成随机密码功能是很容易的,下面的代码给出了完整的实现方法:
publicstaticstring ......
ASP.NET 数据控件:GridView,DataList,Repeater ,DetailsView,FormView。
ASP.NET 数据控件综述:
1.前3个用于呈现多条记录,后面2个用于呈现单条数据明细,即常用的记录明细。
2.GridView
和DetailsView控件的布局固定,自定义数据显示的布局功能有限,一般适合布局简单的数据呈现。3.DataList,Repeater和
FormView数据 ......