zoukankan      html  css  js  c++  java
  • asp.net 2.0中的profile

    <connectStrings>
     
    <clear/>
     
    <add name="MyConnect" connectionstring="data source=(local);integrated security="SSPI"; initial Catalog="aspnetdb"/>
    </connectStrings>

    profile是使用存储用户信息的,那么它和其他的状态管理(view state,session,cookie)又有什么不同呢?
      profile是可以长时间保存用户信息的,而view state 、session、cookie是短时间保持用户信息的。并且profile是用后台数据库作为存储的数据源
     1、profile表现情况
        asp.net profile的目的就是提供一种透明的方式来管理特定的用户信息,不需要用户来写那些连接数据库的类。但是在profile在给与你方便的同时,也会带来一些性能上和稳定性的问题。那么怎么能较好的使用profile,这就要取决于你用profile存储多少数据,和你用profile对象的频率。
    那么介绍一下profile是怎么进入页面的生命周期的?
        1、首先在第一次你代码中接触profile对象时,asp.net会将当前用户的所有profile信息抓出来,从那以后你要读取profile信息就不要数据库操作了
        2、如果你改变任何profile的数据,这个更新是直到页面处理完成以后才开始,在(prerender,prerendercomplete,unload)事件出发以后,profile才写回数据库,因此多步改变就变成了一步操作,如果你改变profile数据,没有数据库操作会发生。
    从性能的角度出发,在以下情况profile 会变现的很好:
    1、你有相对少量的页面接触profile的数据。
    2、你存储少量的数据
    当是以下的情况时其表现的就不怎么好
    1、你有许多页面要使用profile的数据
    2、你在profile中存储了大量的数据
    如果需要使用profiles,你就需要做以下步骤来进行配置
    1、打开你网站的验证功能
    2、配置你profile的provider(如果你使用SQL SERVER 2005 Express Edition。这一步可以省略。因为默认情况下已经开启)
    3、创建profile表格(如果你使用sql server 2005express edition这一步是不需要的)
    4、定义profile属性
    5、在你的web page 代码中使用profile属性。
    接下来我分开描述这五步:
    1、打开网站的验证功能

    1<authentication mode="Forms">
    2
    3</authentication>
    4
    这样就将验证功能打开了,这里mode可以使forms也可以是windows
    2、配置你provider,其实配置profile的provider和配置membership、role的provider可以说是一样的,因为配置这个provider也就是告诉我上层的api将调用我写的哪个类中的函数,那么我们这里采用的类都是使用asp.net 2.0中已经写好的,它在空间System.Web.Profile.SqlProfileProvider中,如果我们是使用sql server 2005express Edition就不需要配置他是自动生成的。如果你是使用sql server 2005 正式版或更老的版本那么就需要自己手动配置以下,
    以下是其配置的两种:
    1、如果是sql server 2005正式版的话,就只需要配置 连接字符串就行了,因为默认的连接数据源服务器是sqlserver/express,所以需要配置字符串。
    1<connectStrings>
    2 <clear/>
    3 <add name="MyConnect" connectionstring="data source=(local);integrated security="SSPI"; AttachDBFileName=|DataDirectory|aspnetdb.mdf;"
    4</connectStrings>
    2、如果是server 2000的话,由于没有attachFileName这个属性所以,就需要指定数据库的名字,只就需要首先在数据库中使用aspnet_regsql.exe这个工具在数据库中注册。
    1<connectStrings>
    2<clear/>
    3 <add name="MyConnect" connectionstring="data source=(local);integrated security="SSPI"; initial Catalog="aspnetdb"/>
    4</connectStrings>

    连接字符串配置好后就需要在profile的provider的连接字符串运用上来,
    1<profile default provider="MyProfile">
    2  <providers>
               <clear/>
    3    <add name="MyProfile" type="System.Web.Profile.SqlProfileProvider" connectionStringName="MyConnect"
    4  applicationName="Your application name"/>
    5  </providers>
    6</profile>
    7
    3、手动创建profile的表格
      其实说手动也不叫手动,就是使用aspnet_regsql.exe工具,当中也自己单击几下向导按钮。
    然后你就可以在你的web.config文件添加profile属性了。

    二、profile数据库
    数据库中用于profile的表格牵涉到了四张表aspnet_Applications、aspnet_Profile、aspnet_SchemaVersions、aspnet_Users,下面是正散当中三张表的关系




    三、定义profile属性
    在profile中存储信息之前必须要在web.config中定义属性
    <properies>
      <add name="firstName"/>
      <add name="lastName"/>
    </properies>
    你还可以指定存储数据的类型,如果你不指定那么它就以string的格式存储。向属性还可以增加其他的属性。

  • 相关阅读:
    jQuery 淡入淡出
    (Windows窗体)循环动态绑定根节点及子节点
    C# 语音读取
    js禁用&启用某个按钮
    AWS DescribeDBInstances API 无法查询到 DBInstanceArn 参数
    Python 设置S3文件属性中元数据的Content-Encoding值
    Pyhton 批量重命名 AWS S3 中的文件
    Python 控制(SSM)AWS Systems Manager
    Python 根据AWS EC2设置的标签获取正在运行的instancesId
    python 'wb' 模式写入文件怎么输出回车
  • 原文地址:https://www.cnblogs.com/yukun/p/489443.html
Copyright © 2011-2022 走看看