C# Sql配置文件提供程序

C# Sql配置文件提供程序,c#,asp.net,vb.net,C#,Asp.net,Vb.net,我正在web应用程序中使用.NET 4和VB.NET 我已经创建了所有SQL成员表等。。通过使用aspnet_regsql.exe 我可以登录,添加用户,删除用户,添加角色等 现在,我尝试使用profile表添加一些字段,这些字段需要在注册时添加到新创建的用户 在我的网络配置中,我现在有了这个 <profile defaultProvider="MyProfileProvider" > <providers> <

我正在web应用程序中使用.NET 4和VB.NET

我已经创建了所有SQL成员表等。。通过使用aspnet_regsql.exe

我可以登录,添加用户,删除用户,添加角色等

现在,我尝试使用profile表添加一些字段,这些字段需要在注册时添加到新创建的用户

在我的网络配置中,我现在有了这个

<profile defaultProvider="MyProfileProvider" >
            <providers>
                <clear />
                <add name="MyProfileProvider"
                     connectionStringName="DbConnString"
                     applicationName="/"
                     type="System.Web.Profile.SqlProfileProvider"/>
              </providers>
            <properties>
                <add name="OrganizationId" allowAnonymous="false" type="System.Int16" />
            </properties>
        </profile>

然而,我现在不知道如何使用它。如果我从我的代码中尝试
Profile.OrganizationId
这不是Profile对象的一部分

如果我尝试
HttpContext.Current.Profile.SetPropertyValue(“OrganizationId”,OrgId)
它会工作

有一种简单的方法可以访问概要文件方法吗

还有。。虽然我可以看到aspnet_Profile表中的属性值设置为115,但当我尝试通过
HttpContext.Current.Profile.GetPropertyValue(“OrganizationId”)
获取值时,结果是0

没有人对此有任何想法?

我发现了问题

  • 我正在使用
    HttpContext.Current.Profile.SetPropertyValue()
    创建属性,我当然登录了该属性!!不是新创建的用户!!我是傻瓜
  • 在使用set propertyValue()方法之后,我没有调用.Save()方法
  • 因此,最终代码如下所示:

    网络配置

    <profile defaultProvider="AspNetSqlProfileProvider" enabled="true" automaticSaveEnabled="true" >
    <providers>
    <clear />
    <add name="AspNetSqlProfileProvider"
    connectionStringName="DbConnString"
    applicationName="MyApplication"
    type="System.Web.Profile.SqlProfileProvider"/>
    </providers>
    <properties>
    <add name="PropertyName" allowAnonymous="false" type="System.Int16" />
    </properties>
    </profile>
    
    获取属性值

    Dim MyProfile As ProfileBase
    MyProfile = ProfileBase.Create(Membership.GetUser().UserName)
    Myproeprty = MyProfile.GetPropertyValue("PropertyName")
    

    Hi William的可能复制品,可能是复制品,但另一个问题并不能解决我的问题。我可以将配置文件的属性保存到数据库中,我可以打开数据库表并查看是否有一行包含我保存的属性值,但当我尝试检索该值时,得到的是0,而不是115,我尝试按如下方式获取该属性:HttpContext.Current.profile.GetPropertyValue(“OrganizationId”)
    Dim MyProfile As ProfileBase
    MyProfile = ProfileBase.Create(Membership.GetUser().UserName)
    Myproeprty = MyProfile.GetPropertyValue("PropertyName")