web.config中的profile

时间:2021-10-24 18:11:31

aspnet_regsql命令创建需要的表结构

web.config中的profile

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

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

web.config中的profile

web.config中的profile