SQL配置文件提供者 [英] Sql Profile Provider

查看:126
本文介绍了SQL配置文件提供者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DOT NET 4和VB.NET在Web应用程序。

I am using DOT NET 4 and VB.NET in a web application.

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

I have created all the SQL membership tables etc.. by using aspnet_regsql.exe

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

I can login, add user, delete users add roles etc...

现在我想使用的配置文件表添加一些字段,我需要被添加到注册后,新创建的用户。

Now I am trying to use the profile table to add some fields I need to be added to the newly created user upon registration.

在我的web配置我现在有这个

in my web config I now have this

<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>

不过,我不能想出现在如何使用它。如果从我的code我尝试 Profile.OrganizationId 这是不是配置文件对象的一部分。

however I cannot figure out now how to use it. If from my code i try Profile.OrganizationId this is not part of the profile object.

如果我尝试 HttpContext.Current.Profile.SetPropertyValue(OrganizationId,ORGID)它的工作原理。

if I try HttpContext.Current.Profile.SetPropertyValue("OrganizationId", OrgId) it works.

有是访问配置文件方法的简单方法?

There is a simple way to access the Profile methods?

还..虽然我可以在aspnet_Profile表设置为115,当我试图让通过 HttpContext.Current.Profile.GetPropertyValue(OrganizationId)中的值我得到0的结果???

Also.. although I can see the property value in the aspnet_Profile table set to 115, when I try to get the value by HttpContext.Current.Profile.GetPropertyValue("OrganizationId") I get 0 as result ???

没有人有这个什么想法?

nobody has any idea on this ?

推荐答案

我发现这个问题(S)


  1. 我用创建属性 HttpContext.Current.Profile.SetPropertyValue()这当然是我登录!没有新创建的用户!假我!

  2. 我没有用集后调用.Save()方法为PropertyValue()方法

  1. I was creating the property using HttpContext.Current.Profile.SetPropertyValue() which of course was ME logged in !! not the newly created user !! Dummy I am !!
  2. I was not calling the .Save() method after using the set propertyValue() method

所以最后code是如下:

So the final code is as follow:

WEB CONFIG

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")

这篇关于SQL配置文件提供者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆