日期:2014-05-17  浏览次数:20477 次

网站项目中Profile的引用问题
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;