首页 > Web开发 > 详细

web.config中的profile

时间:2015-04-28 17:29:29      阅读:294      评论:0      收藏:0      [点我收藏+]

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中的信息会持久化到指定的数据库中。

技术分享

技术分享

web.config中的profile

原文:http://www.cnblogs.com/goodlucklzq/p/4403030.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!