我在网络应用程序中使用DOT NET 4和VB.NET。
我已经使用aspnet_regsql.exe
创建了所有SQL成员资格表等我可以登录,添加用户,删除用户添加角色等...
现在我正在尝试使用配置文件表添加一些我需要在注册时添加到新创建的用户的字段。
在我的网络配置中,我现在有了这个
<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
,那么这不是个人资料对象的一部分。
如果我尝试HttpContext.Current.Profile.SetPropertyValue("OrganizationId", OrgId)
它可行。
有一种访问Profile方法的简单方法吗?
另外..虽然我可以看到aspnet_Profile表中的属性值设置为115,但当我尝试通过HttpContext.Current.Profile.GetPropertyValue("OrganizationId")
获取值时,我得到0作为结果???
没有人对此有任何想法?
答案 0 :(得分:0)
我找到了问题
HttpContext.Current.Profile.SetPropertyValue()
创建属性,当然我已登录!!不是新创建的用户!!假的我是!! 所以最终的代码如下:
WEB CONFIG
<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(CreateUserWizard.UserName)
PropertyValue =whatever you want
MyProfile.SetPropertyValue("PropertyName", PropertyValue)
MyProfile.Save()
获得物业价值
Dim MyProfile As ProfileBase
MyProfile = ProfileBase.Create(Membership.GetUser().UserName)
Myproeprty = MyProfile.GetPropertyValue("PropertyName")