在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ C#/ ASP.NET個(gè)性化
ASP.NET調(diào)試
ASP.NET Web Services
ASP.NET緩存
ASP.NET多線程
ASP.NET面板控件
ASP.NET數(shù)據(jù)綁定
ASP.NET數(shù)據(jù)源
ASP.NET個(gè)性化
ASP.Net教程
ASP.NET Ajax控件
ASP.NET生命周期
ASP.NET HTML服務(wù)器
ASP.NET簡(jiǎn)介
ASP.NET驗(yàn)證器
ASP.NET多視圖
ASP.NET網(wǎng)站配置
ASP.NET錯(cuò)誤管理
ASP.NET自定義控件
ASP.NET LINQ
ASP.NET AdRotator控件
ASP.NET客戶端
ASP.NET文件上傳
ASP.NET服務(wù)器控件
ASP.NET開(kāi)發(fā)環(huán)境配置
ASP.NET管理狀態(tài)
ASP.NET服務(wù)端
ASP.NET數(shù)據(jù)庫(kù)訪問(wèn)(Access)
ASP.NET基本控件
ASP.NET安全
ASP.NET指令
ASP.NET事件處理
ASP.NET第一個(gè)程序
ASP.NET日歷控件

ASP.NET個(gè)性化

網(wǎng)站設(shè)計(jì)是為用戶提供重復(fù)訪問(wèn)的個(gè)性化使得網(wǎng)站能夠記住用戶身份和其他信息細(xì)節(jié),并為每個(gè)用戶呈現(xiàn)個(gè)人化的環(huán)境。

ASP.NET提供個(gè)性化網(wǎng)站來(lái)為特定客戶的喜好和偏好地提供服務(wù)。

了解配置文件

ASP.NET個(gè)性化服務(wù)基于用戶配置文件。 用戶配置文件定義了該網(wǎng)站所需用戶的信息種類。 例如,姓名,年齡,地址,出生日期和電話號(hào)碼。

此信息在應(yīng)用程序的web.config文件中定義,ASP.NET運(yùn)行時(shí)讀取并使用它。這項(xiàng)工作是由個(gè)性化提供程序來(lái)完成的。

從用戶數(shù)據(jù)中獲取的用戶配置文件存儲(chǔ)在由ASP.NET創(chuàng)建的默認(rèn)數(shù)據(jù)庫(kù)中。 您可以創(chuàng)建自己的數(shù)據(jù)庫(kù)來(lái)存儲(chǔ)配置文件。配置文件數(shù)據(jù)定義存儲(chǔ)在配置文件web.config中。

示例

下面創(chuàng)建一個(gè)ASP.Net空網(wǎng)站示例項(xiàng)目:Personalization ,我們希望應(yīng)用程序記住用戶詳細(xì)信息,如姓名,地址,出生日期等。在web.config文件中的<system.web>元素節(jié)點(diǎn)下添加配置文件詳細(xì)信息。

<configuration>
<system.web>

<profile>
   <properties>
      <add name="Name" type ="String"/>
      <add name="Birthday" type ="System.DateTime"/>

      <group name="Address">
         <add name="Street"/>
         <add name="City"/>
      </group>

   </properties>
</profile>

</system.web>
</configuration>

web.config文件中定義配置文件時(shí),配置文件可以通過(guò)當(dāng)前HttpContext中的Profile屬性使用,也可以通過(guò)頁(yè)面使用。

按照配置文件中的定義添加文本框以接受用戶輸入,并添加一個(gè)用于提交數(shù)據(jù)的按鈕:

更新Page_load事件方法以顯示配置文件信息:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            ProfileCommon pc = this.Profile.GetProfile(Profile.UserName);

            if (pc != null)
            {
                this.txtname.Text = pc.Name;
                this.txtaddr.Text = pc.Address.Street;
                this.txtcity.Text = pc.Address.City;
                this.Calendar1.SelectedDate = pc.Birthday;
            }
        }
    }

提交按鈕編寫(xiě)以下處理程序,將用戶數(shù)據(jù)保存到配置文件中:

    protected void Button1_Click(object sender, EventArgs e)
    {
        ProfileCommon pc = this.Profile.GetProfile(Profile.UserName);

        if (pc != null)
        {
            pc.Name = this.txtname.Text;
            pc.Address.Street = this.txtaddr.Text;
            pc.Address.City = this.txtcity.Text;
            pc.Birthday = this.Calendar1.SelectedDate;

            pc.Save();
        }
    }
`

當(dāng)頁(yè)面首次執(zhí)行時(shí),用戶需要輸入信息。 但是,下次用戶的詳細(xì)信息會(huì)自動(dòng)加載。

add元素的屬性

除了已經(jīng)使用的名稱和類型屬性之外,還有<add>元素的其他屬性。下表說(shuō)明了其中的一些屬性:

編號(hào) 屬性 描述
1 name 屬性的名稱。
2 type 默認(rèn)情況下,類型是字符串,但它允許任何完全限定的類名作為數(shù)據(jù)類型。
3 serializeAs 序列化此值時(shí)使用的格式。
4 readOnly 只讀配置文件值不能更改,默認(rèn)情況下該屬性為false。
5 defaultValue 如果配置文件不存在或沒(méi)有信息,則使用默認(rèn)值。
6 allowAnonymous 一個(gè)布爾值,指示此屬性是否可以與匿名配置文件一起使用。
7 Provider 應(yīng)該用來(lái)管理這個(gè)屬性的配置文件提供程序。

匿名個(gè)性化

匿名個(gè)性化允許用戶在識(shí)別自己之前個(gè)性化網(wǎng)站。 例如,Amazon.com允許用戶在登錄前添加購(gòu)物車中的物品。要啟用此功能,可以將web.config文件配置為:

<anonymousIdentification enabled ="true" cookieName=".ASPXANONYMOUSUSER"
   cookieTimeout="120000" cookiePath="/" cookieRequiresSSL="false"
   cookieSlidingExpiration="true" cookieprotection="Encryption"
   coolieless="UseDeviceProfile"/>