web.config文件
- HTML code
<?xml version="1.0"?><!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --><configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.web> <authorization> <deny users="?" /> </authorization> <authentication mode="Forms" /> <compilation debug="true" targetFramework="4.0"/> <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15"> <providers> <clear /> <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="NorthwindConnectionString" applicationName="northWind" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Hashed" /> </providers> </membership> <roleManager defaultProvider="SqlProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" > <providers> <add name="SqlProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="NorthwindConnectionString" applicationName="northWind" /> </providers> </roleManager> </system.web> <connectionStrings> <add name="NorthwindConnectionString" connectionString="Data Source=XXX-PC;Initial Catalog=aspnetdb;Integrated Security=True;" providerName="System.Data.Sqlclient" /> [color=#FF0000]<profile> <properties> <add name="Country"/> <add name="Visits" type="System.Int32" defaultValue="0"/> <add name="LastVisit" type="System.DateTime"/> </properties> </profile>[/color] <add name="EventsConnectionString" connectionString="Data Source=XXX-PC;Initial Catalog=BegVCSharpEvents;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>
红色部分为Profile的代码配置
ProfileDemo.aspx文件
- C# code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class ProfileDemo : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DropDownListCountries.SelectedValue = Profile.Country; } LabelLastVisit.Text = Profile.LastVisit.ToLongTimeString(); LabelVisitCount.Text = Profile.Visits.ToString(); LabelSelectedCountry.Text = Profile.Country; Profile.Visits++; Profile.LastVisit = DateTime.Now; Profile.Save(); } protected void onCountrySelection(object sender, EventArgs e) { Profile.Country = this.DropDownListCountries.SelectedItem.Value; Profile.Save(); }}
在ProfileDemo.aspx文件中,不能对Profile的属性进行引用,
出现“所引用内容是否缺少using 引用或程序集指令”错误,还有个我不是很清楚关于配置文件中Profile代码段的所放的具体位置如何。