文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页技术开发.Net 专栏 → ASP.net 2.0 学习如何用户配置文件

ASP.net 2.0 学习如何用户配置文件

时间:2009/11/10 12:02:00来源:本站整理作者:我要评论(0)

概念: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配置文件需另外的配置额外的属性,具体细节,下次马上更新。
-

 

相关视频

    没有数据

相关阅读 ie6下面asp.net mvc3 部署应用程序在asp.net mvc中实现右键菜单和简单的分页教程ASP.NET中MVC框架模式方法如何实现分享ASP.NET 2.0 中保护机密数据ASP.NET配置文件Web.configASP.NET 2.0 AJAX中Webservice调用方法ASP.NET 的安全认证实现ASP.NET生成随机密码功能

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 什么是.NET中的TDD?ASP.NET AJAX入门简介 WebMatrix入门教程VC++2008中如何调用GetOpenFileName打开文件PlaySound函数在VC++6.0中如何播放音乐及声请问VC++回调函数怎么用

人气排行 嵌入式实时操作系统VxWorks入门教程ArrayList 与 string、string[] 的转换C#遍历整个文件夹及子目录的文件代码WebMatrix入门教程asp.net判断文件或文件夹是否存在c#判断数据NULL值的方法vc++6.0怎么写Windows简单窗口代码.net解决数据导出excel时的格式问题