profile类来实现匿名用户登录 把登录信息传放到 SQL2000里的aspnet数据库中,这个是匿名用户的例子
注意:即使用户关闭了应用程序(或游览器)在重新到开 一样可以得到匿名用户在网站上的信息
此程序在实现的时候必须先运行 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727路径下的aspnet_regsql.exe
文件建立SQL2000中的aspnetdb数据库 来存放匿名用户信息

Web.config配置文件代码:
aspx.cs 文件代码:
注意:即使用户关闭了应用程序(或游览器)在重新到开 一样可以得到匿名用户在网站上的信息
此程序在实现的时候必须先运行 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727路径下的aspnet_regsql.exe
文件建立SQL2000中的aspnetdb数据库 来存放匿名用户信息
Web.config配置文件代码:
1
<configuration>
2
<appSettings/>
3
<connectionStrings>
4
<add name="SqlServices" connectionString="server=.;database=aspnetdb;uid=sa;pwd=;"
5
providerName="System.Data.SqlClient"/>
6
</connectionStrings>
7
<system.web>
8
<anonymousIdentification enabled ="true"/>
9
<profile defaultProvider ="SqlProvider">
10
<properties>
11
<add name="Name" allowAnonymous="true"/>
12
<add name="LastSubmit" allowAnonymous="true" type="System.DateTime"/>
13
<group name="Address">
14
<add name="City" allowAnonymous="true"/>
15
<add name="PostalCode" allowAnonymous="true"/>
16
</group>
17
</properties>
18
<providers>
19
<clear/>
20
<add name="SqlProvider" connectionStringName="SqlServices"
21
type="System.Web.Profile.SqlProfileProvider" applicationName="TestApp"/>
22
</providers>
23
</profile>
<configuration>2
<appSettings/>3
<connectionStrings>4
<add name="SqlServices" connectionString="server=.;database=aspnetdb;uid=sa;pwd=;"5
providerName="System.Data.SqlClient"/>6
</connectionStrings>7
<system.web>8
<anonymousIdentification enabled ="true"/>9
<profile defaultProvider ="SqlProvider">10
<properties>11
<add name="Name" allowAnonymous="true"/>12
<add name="LastSubmit" allowAnonymous="true" type="System.DateTime"/>13
<group name="Address">14
<add name="City" allowAnonymous="true"/>15
<add name="PostalCode" allowAnonymous="true"/>16
</group>17
</properties>18
<providers>19
<clear/>20
<add name="SqlProvider" connectionStringName="SqlServices" 21
type="System.Web.Profile.SqlProfileProvider" applicationName="TestApp"/>22
</providers>23
</profile>aspx.cs 文件代码:
1
protected void Page_Load(object sender, EventArgs e)
2
{
3
if (!this.IsPostBack)
4
{
5
DisPlayProfileInfo();
6
}
7
}
8
private void DisPlayProfileInfo()
9
{
10
Response.Write("<font color='green' size='3'>SettingsProperty对象的数目:" + ProfileCommon.Properties.Count + "</font>");
11
txtName.Text = Profile.Name;
12
txtCity.Text = Profile.Address.City;
13
txtPost.Text = Profile.Address.PostalCode;
14
DateTime time = Profile.LastSubmit;
15
if (time.Year == 1)
16
{
17
lblTime.Text = "空";
18
}
19
else
20
{
21
lblTime.Text = time.ToString();
22
}
23
}
24
protected void Button1_Click(object sender, EventArgs e)
25
{
26
Response.Write("<font color='red' size='3'>SettingsProperty对象的数目:" + ProfileCommon.Properties.Count+"</font>");
27
if (txtName.Text != "" && txtCity.Text != "" && txtPost.Text != "")
28
{
29
Profile.Name = txtName.Text;
30
Profile.Address.City = txtCity.Text;
31
Profile.Address.PostalCode = txtPost.Text;
32
Profile.LastSubmit = DateTime.Now;
33
}
34
else
35
{
36
Response.Write("<script>alert('请在文本框输入信息')</script>");
37
}
protected void Page_Load(object sender, EventArgs e)2
{3
if (!this.IsPostBack)4
{5
DisPlayProfileInfo();6
}7
}8
private void DisPlayProfileInfo()9
{10
Response.Write("<font color='green' size='3'>SettingsProperty对象的数目:" + ProfileCommon.Properties.Count + "</font>");11
txtName.Text = Profile.Name;12
txtCity.Text = Profile.Address.City;13
txtPost.Text = Profile.Address.PostalCode;14
DateTime time = Profile.LastSubmit;15
if (time.Year == 1)16
{17
lblTime.Text = "空";18
}19
else20
{21
lblTime.Text = time.ToString();22
}23
}24
protected void Button1_Click(object sender, EventArgs e)25
{26
Response.Write("<font color='red' size='3'>SettingsProperty对象的数目:" + ProfileCommon.Properties.Count+"</font>");27
if (txtName.Text != "" && txtCity.Text != "" && txtPost.Text != "")28
{29
Profile.Name = txtName.Text;30
Profile.Address.City = txtCity.Text;31
Profile.Address.PostalCode = txtPost.Text;32
Profile.LastSubmit = DateTime.Now; 33
}34
else35
{36
Response.Write("<script>alert('请在文本框输入信息')</script>");37
}

浙公网安备 33010602011771号