怎样扩张用户资料信息?
在userprofile类中增加属性,然后编译成dll,copy到bin目录中,在web.config中增加profile属性即可。
更新users表里面的数据。
' Created seperate method to save profile data. SaveProfileProperty(objUser.Membership.Username, objUser.Profile.ProfileProperties)
更新web。Config文件里设置的字段,
实现代码如下:
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表里面的key,value通过调用item(key)=value方法
放入pb hash表中
然后调用pb。Save()保存hash表。
用户注册信息的最后一步是调用membership.updateuser(msuser)方法
这样注册用户信息已放入三个表中:
users,aspnet_membership,aspnet_profile