web.config中的profile

aspnet_regsql命令创建需要的表结构

 1  public class UserProfile:ProfileBase
 2     {
 3         [SettingsAllowAnonymous(true)]  //默认匿名用户不能访问
 4         public string MyTest 
 5         {
 6             get
 7             {
 8                 return (string)base["mytest"];
 9             }
10             set
11             {
12                 base["mytest"] = value;
13             }
14         }
15 
16     }
View Code
 1   <system.web>
 2         <compilation debug="true" targetFramework="4.0" />
 3         <anonymousIdentification enabled="true"/>
 4         <authentication mode="Forms">
 5             <forms loginUrl="a.html"></forms>
 6         </authentication>
 7         <profile defaultProvider="mySqlProfileProvider" inherits="WebApplication1.UserProfile">
 8             <providers>
 9                 <clear/>
10                 <add name="mySqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" applicationName="aa.com"  connectionStringName="aspnetdb"    description="mySqlProfileProvider"/>
11             </providers>
12             <properties>
13                 <add name="A" /> <!--默认是string类型,匿名用户能够访问-->
14                 <add name="B" type="System.Int32"/>
15                 <add name="C" allowAnonymous="false" />
16                 <group name="lists">
17                     <add name="a" type="int"/>
18                 </group>
19             </properties>
20         </profile>
21     </system.web>
22     <connectionStrings>
23         <add name="aspnetdb" connectionString="Data Source=.;Initial Catalog=aspnetdb;Persist Security Info=True;User ID=sa;Password=123" providerName="System.Data.SqlClient"/>
24     </connectionStrings>
View Code

在properties中添加的name会放到默认生成的对象ProfileCommon中,ProfileCommon默认继承ProfileBase,但是可以自定义Profile,此时ProfileCommon会继承自定义的Profile【如上文中的UserProfile】。Profile中的信息会持久化到指定的数据库中。

转载于:https://www.cnblogs.com/goodlucklzq/p/4403030.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值