现在的位置: 首页 > 综合 > 正文

dotnetnuke 里profile 的使用

2013年02月22日 ⁄ 综合 ⁄ 共 2123字 ⁄ 字号 评论关闭
 

怎样扩张用户资料信息?

userprofile类中增加属性,然后编译成dllcopybin目录中,在web.config中增加profile属性即可。

 

DataProvider.Instance.UpdateUser(objUser.UserID, objSecurity.InputFilter(objUser.Profile.FirstName, PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoMarkup), objSecurity.InputFilter(objUser.Profile.LastName, PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoMarkup), objUser.Membership.Email)

 

更新users表里面的数据。

 ' Created seperate method to save profile data. SaveProfileProperty(objUser.Membership.Username, objUser.Profile.ProfileProperties)

更新webConfig文件里设置的字段,

实现代码如下:

  Private Sub SaveProfileProperty(ByVal userName As String, ByVal propHash As Hashtable)

            Dim objProfile As AspNetProfile.ProfileBase

            Dim objSecurity As New PortalSecurity

 

            objProfile = AspNetProfile.ProfileBase.Create(userName, True)

 

            'Looping through each key in profile hashtable.

            'Each key is profile property name.

            For Each key As Object In propHash.Keys

                'checking if property's datatype is string.

                'if it is string then we do input filter on value.

 

                If AspNetProfile.ProfileBase.Properties(key.ToString()).PropertyType Is GetType(String) Then

                    'Checking if value is set or not? if value is set then do input filter

                    'otherwise assign Nullstring.

                    If propHash.ContainsKey(key) AndAlso Not propHash(key) Is Nothing Then

                        objProfile(key.ToString()) = objSecurity.InputFilter(propHash(key).ToString(), PortalSecurity.FilterFlag.NoScripting Or PortalSecurity.FilterFlag.NoMarkup)

                    Else

                        objProfile(key.ToString()) = Null.NullString

                    End If

                Else

                    objProfile(key.ToString()) = Null.SetNull(propHash(key), AspNetProfile.ProfileBase.Properties(key.ToString()).PropertyType)

                End If

            Next

            objProfile.Save()

 

        End Sub

       代码分析:

新建一个实例profilebase pb=profilebase.create(name,true)

hash表里面的keyvalue通过调用itemkey=value方法

放入pb hash表中

然后调用pbSave()保存hash表。

 

用户注册信息的最后一步是调用membership.updateuser(msuser)方法

这样注册用户信息已放入三个表中:

usersaspnet_membership,aspnet_profile

抱歉!评论已关闭.