国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ASP.net 2.0 學習如何用戶配置文件(一)

2019-11-17 04:06:02
字體:
來源:轉載
供稿:網友
 概念:PRofile對象提供強類型、可持久化的session狀態表單

Web配置文件節點代碼:<黑白激光傳真一體機>

view plaincopy to clipboardprint?
<profile>   
<properties>   
<add name="firstName"/>   
<add name="lastName"/>   
<add name="numberOfVisits" type="Int32" defaultValue="0"/>   
</properties>   
</profile>  
<profile>
<properties>
<add name="firstName"/>
<add name="lastName"/>
<add name="numberOfVisits" type="Int32" defaultValue="0"/>
</properties>
</profile>

在Web配置文件中定義Profile后,可以使用Profile對象修改其屬性。



asp.net前臺界面調用顯示結果示例代碼:<低速復印機>

view plaincopy to clipboardprint?
<html xmlns="http://www.w3.org/1999/xhtml" >  
<head id="Head1" runat="server">  
    <title>Show Profile</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
       
    First Name:   
    <asp:Label  
        id="lblFirstname"  
        Runat="server" />  
    <br /><br />  
    Last Name:   
    <asp:Label  
        id="lblLastName"  
        Runat="server" />  
    <br /><br />  
    Number of Visits:   
    <asp:Label  
        id="lblNumberOfVisits"  
        Runat="server" />  
           
    <hr />  
       
    <asp:Label  
        id="lblNewFirstName"  
        Text="New First Name:"  
        AssociatedControlID="txtNewFirstName"  
        Runat="server" />  
    <asp:TextBox  
        id="txtNewFirstName"  
        Runat="server" />  
    <br /><br />  
    <asp:Label  
        id="lblNewLastName"  
        Text="New Last Name:"  
        AssociatedControlID="txtNewLastName"  
        Runat="server" />  
    <asp:TextBox  
        id="txtNewLastName"  
        Runat="server" />  
    <br /><br />       
    <asp:Button  
        id="btnUpdate"  
        Text="Update Profile"  
        OnClick="btnUpdate_Click"    
        Runat="server" />  
       
    </div>  
    </form>  
</body>  
</html>  
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Show Profile</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    First Name:
    <asp:Label
        id="lblFirstname"
        Runat="server" />
    <br /><br />
    Last Name:
    <asp:Label
        id="lblLastName"
        Runat="server" />
    <br /><br />
    Number of Visits:
    <asp:Label
        id="lblNumberOfVisits"
        Runat="server" />
        
    <hr />
    
    <asp:Label
        id="lblNewFirstName"
        Text="New First Name:"
        AssociatedControlID="txtNewFirstName"
        Runat="server" />
    <asp:TextBox
        id="txtNewFirstName"
        Runat="server" />
    <br /><br />
    <asp:Label
        id="lblNewLastName"
        Text="New Last Name:"
        AssociatedControlID="txtNewLastName"
        Runat="server" />
    <asp:TextBox
        id="txtNewLastName"
        Runat="server" />
    <br /><br />    
    <asp:Button
        id="btnUpdate"
        Text="Update Profile"
        OnClick="btnUpdate_Click"
        Runat="server" />
    
    </div>
    </form>
</body>
</html>



ASP.NET后臺屬性賦值示例代碼:

view plaincopy to clipboardprint?
void Page_PreRender()   
{   
   lblFirstname.Text = Profile.firstName;   
   lblLastName.Text = Profile.lastName;   
   Profile.numberOfVisits++;   
   lblNumberOfVisits.Text =Profile.numberOfVisits.ToString();   
}   
  
protected void btnUpdate_Click(object sender, EventArgs e)   
{   
   Profile.firstName = txtNewFirstName.Text;   
   Profile.lastName = txtNewLastName.Text;   
}  
void Page_PreRender()
{
   lblFirstname.Text = Profile.firstName;
   lblLastName.Text = Profile.lastName;
   Profile.numberOfVisits++;
   lblNumberOfVisits.Text =Profile.numberOfVisits.ToString();
}

protected void btnUpdate_Click(object sender, EventArgs e)
{
   Profile.firstName = txtNewFirstName.Text;
   Profile.lastName = txtNewLastName.Text;
}



最后理解Profile屬性是持久化的非常重要。如果為一個用戶設置Profile屬性,那么就是該用戶過500年也不會返回網站,屬性也會保留其值。不想Sess狀態。



默認Profile不支持匿名用戶,如果需支持匿名用戶的話,則在WEB配置文件需另外的配置額外的屬性,具體細節,下次馬上更新。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新源县| 公安县| 安西县| 宁河县| 靖州| 梨树县| 章丘市| 阳高县| 东明县| 雷山县| 五原县| 潜山县| 万宁市| 新兴县| 石首市| 公安县| 南昌市| 东丽区| 大竹县| 依兰县| 理塘县| 万荣县| 静安区| 齐河县| 刚察县| 蒙阴县| 五莲县| 阳信县| 天长市| 肇州县| 徐闻县| 益阳市| 阳山县| 岫岩| 城口县| 南昌市| 会泽县| 大埔区| 北票市| 郧西县| 眉山市|