国产探花免费观看_亚洲丰满少妇自慰呻吟_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配置文件需另外的配置額外的屬性,具體細節,下次馬上更新。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 九台市| 北碚区| 当阳市| 新巴尔虎右旗| 平遥县| 上虞市| 昔阳县| 璧山县| 廊坊市| 万州区| 嘉荫县| 阜阳市| 开远市| 蒲城县| 兴义市| 塔城市| 栾城县| 深水埗区| 忻城县| 深圳市| 怀仁县| 宜宾县| 台北县| 宁津县| 绥棱县| 嘉荫县| 建阳市| 博野县| 盐池县| 南华县| 富民县| 兴文县| 山阳县| 新晃| 汝阳县| 淄博市| 江永县| 长兴县| 达孜县| 琼结县| 黔南|