webconfig中的代码如下:
Code
Code
<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings/>
<connectionStrings>
<add name="SQLProfileConnString" connectionString="server=SQL2005;user id=sa;password=123;database=basedata;min pool size=4;max pool size=4;packet size=3072" providerName="System.Data.SqlClient"></add>
</connectionStrings>
<system.web>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<anonymousIdentification enabled="true"/>
<profile defaultProvider="SqlProvider">
<properties>
<add name="Name" allowAnonymous="true"/>
<add name="LastSubmit" allowAnonymous="true" type="System.DateTime"/>
<group name="Address">
<add name="City" allowAnonymous="true"/>
<add name="PostalCode" allowAnonymous="true"/>
</group>
</properties>
<providers>
<clear/>
<add name="SqlProvider" connectionStringName="SQLProfileConnString" type="System.Web.Profile.SqlProfileProvider" applicationName="ProfileTest"/>
</providers>
</profile>
<membership defaultProvider="SqlMembershipProvider">
<providers>
<add name="SqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="SQLProfileConnString"
applicationName="ProfileTest"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"/>
</providers>
</membership>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode="Forms"/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<compilation debug="true"/></system.web>
</configuration>
Code
<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件以外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表在
machine.config.comments 中,该文件通常位于
\Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
<appSettings/>
<connectionStrings>
<add name="SQLProfileConnString" connectionString="server=SQL2005;user id=sa;password=123;database=basedata;min pool size=4;max pool size=4;packet size=3072" providerName="System.Data.SqlClient"></add>
</connectionStrings>
<system.web>
<!--
设置 compilation debug="true" 将调试符号插入
已编译的页面中。但由于这会
影响性能,因此只在开发过程中将此值
设置为 true。
-->
<anonymousIdentification enabled="true"/>
<profile defaultProvider="SqlProvider">
<properties>
<add name="Name" allowAnonymous="true"/>
<add name="LastSubmit" allowAnonymous="true" type="System.DateTime"/>
<group name="Address">
<add name="City" allowAnonymous="true"/>
<add name="PostalCode" allowAnonymous="true"/>
</group>
</properties>
<providers>
<clear/>
<add name="SqlProvider" connectionStringName="SQLProfileConnString" type="System.Web.Profile.SqlProfileProvider" applicationName="ProfileTest"/>
</providers>
</profile>
<membership defaultProvider="SqlMembershipProvider">
<providers>
<add name="SqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="SQLProfileConnString"
applicationName="ProfileTest"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"/>
</providers>
</membership>
<!--
通过 <authentication> 节可以配置 ASP.NET 使用的
安全身份验证模式,
以标识传入的用户。
-->
<authentication mode="Forms"/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
开发人员通过该节可以配置
要显示的 html 错误页
以代替错误堆栈跟踪。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<compilation debug="true"/></system.web>
</configuration>
Default.aspx中的代码:
Code
<%@ 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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
上次提交:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
用户姓名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
所在国家:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
邮政编码:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click" /></div>
</form>
</body>
</html>
<%@ 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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
上次提交:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
用户姓名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
所在国家:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
邮政编码:<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click" /></div>
</form>
</body>
</html>
Default.aspx.cs中的代码:
Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Profile;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DisPlayProfileInfo();
}
}
private void DisPlayProfileInfo()
{
Response.Write("<font color='green' size='3'>SettingsProperty对象的数目:" + ProfileCommon.Properties.Count + "</font>");
TextBox1.Text = Profile.Name;
TextBox2.Text = Profile.Address.City;
TextBox3.Text = Profile.Address.PostalCode;
DateTime time = Profile.LastSubmit;
if (time.Year == 1)
{
Label1.Text = "空";
}
else
{
Label1.Text = time.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<font color='red' size='3'>SettingsProperty对象的数目:" + ProfileCommon.Properties.Count + "</font>");
if (TextBox1.Text != "" && TextBox2.Text != "" && TextBox3.Text != "")
{
Profile.Name = TextBox1.Text;
Profile.Address.City = TextBox2.Text;
Profile.Address.PostalCode = TextBox3.Text;
Profile.LastSubmit = DateTime.Now;
}
else
{
Response.Write("<script>alert('请在文本框输入信息')</script>");
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Profile;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DisPlayProfileInfo();
}
}
private void DisPlayProfileInfo()
{
Response.Write("<font color='green' size='3'>SettingsProperty对象的数目:" + ProfileCommon.Properties.Count + "</font>");
TextBox1.Text = Profile.Name;
TextBox2.Text = Profile.Address.City;
TextBox3.Text = Profile.Address.PostalCode;
DateTime time = Profile.LastSubmit;
if (time.Year == 1)
{
Label1.Text = "空";
}
else
{
Label1.Text = time.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<font color='red' size='3'>SettingsProperty对象的数目:" + ProfileCommon.Properties.Count + "</font>");
if (TextBox1.Text != "" && TextBox2.Text != "" && TextBox3.Text != "")
{
Profile.Name = TextBox1.Text;
Profile.Address.City = TextBox2.Text;
Profile.Address.PostalCode = TextBox3.Text;
Profile.LastSubmit = DateTime.Now;
}
else
{
Response.Write("<script>alert('请在文本框输入信息')</script>");
}
}
}
login.aspx中的代码:
Code
<%@ Page Language="C#" %>
<!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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server">
</asp:Login>
<br />
<br />
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<!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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server">
</asp:Login>
<br />
<br />
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>
点击“提交”按钮,将会在aspnet_Profile、aspnet_Users、aspnet_Applications三张表中插入数据;
aspnet_Profile表中UserId的产生规则既是petshop4.0中的Username的产生规则;
注册新用户,将在aspnet_Membership、aspnet_Users、aspnet_Applications三张表中插入数据。