473,842 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simplest Method to Implement a Custom Profile Provider

karlr
5 New Member
OK, I know this has been discussed in multiple posts. However, I still have not seen a good example.

That is, I have a custom Membership provider using the ASP.NET 2.0 controls. I am restricted to using an exising SQL 2000 database, which works for the basic fields (username, pw, email, etc). However, I need to add more information (phone number, age, etc).

In reading the existing discussions, I can see the valid reasons for storing this information in a profile. I have downloaded and tried to use the MS Access Provider sample, with little success (probably because it is in C, and I only really know VB). I am struggling to get the basics working, such as defining a location to store the profile information (profile provider?) and how to correctly associate my existing membership data with this new profile data. I think I should link it via a UserID or something similar, but I am unable to figure out how to do this via code.

I would greatly appreciate it if anyone could give me any guidance to a VB-specific example of how to do this or anything else that might help me. Thank you!
Feb 19 '07 #1
10 7258
willakawill
1,646 Top Contributor
moving you to a different forum where you might get a better response
Feb 20 '07 #2
jhardman
3,406 Recognized Expert Specialist
I am struggling to get the basics working, such as defining a location to store the profile information (profile provider?) and how to correctly associate my existing membership data with this new profile data. I think I should link it via a UserID or something similar, but I am unable to figure out how to do this via code.

I would greatly appreciate it if anyone could give me any guidance to a VB-specific example of how to do this or anything else that might help me. Thank you!
It's easiest if you can store them as different tables in the same database, then you can open them with a single relational query using the same syntax you had in the asp file you inherited. If the two tables are called "members" and "profiles", and the field names that match are "userID" and "memberNum" then the query looks like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM members, profiles WHERE userID = memberNum
  2.  
A lot of people like to give the matching fields matching names, but then you need to phrase the query like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM members, profiles WHERE members.userID = profiles.userID
  2.  
and I think the first way is better.

Is that enough for you to go on, or do you need more?
Feb 20 '07 #3
karlr
5 New Member
jhardman,

First off, Thank You very much for your reply. You helped clear up how to setup & query the tables in the database. However, I need more help on the front-end (VB/ASP.NET) portion.

As I understand it, I have to define a profile provider and then add the fields that the profile will contain. I added these to my web.config file, which worked (that is, no errors). But I still could not access the fields of the profile in my code. I have seen examples where they did something like
profile.Age = "23"
profile.Zip = "34243"
And the intellisense in VS picked these up in the demo projects I downloaded. In my project I kept getting errors & intellisense didn't function - as if the references in the web.config file did not exist. I am not on my development machine right now, so I can't give an exact post of what my code looks like right now - if posting it would help debug, please let me know & I will repost.

I have been having a hard time finding a walkthrough or example where someone added a profile provider to an exising (or brand-new) project. I would GREATLY appreciate any additional guidance or information you could give me.

Thank you again.
Feb 21 '07 #4
jhardman
3,406 Recognized Expert Specialist
However, I need more help on the front-end (VB/ASP.NET) portion.
I just code in notepad, but I'll help if I can.
As I understand it, I have to define a profile provider and then add the fields that the profile will contain. I added these to my web.config file, which worked (that is, no errors). But I still could not access the fields of the profile in my code. I have seen examples where they did something like
I've never used it, but I thought a web.config file just stored a reference for something that had to already exist. I thought you would need to also go into, say sql server, and add a new table in your database with the fields in question. There are SQL statements for adding a field to a table, but I have never bothered with that, and I don't remember what they are. I don't think there is a statement for adding a new table. Anyone else reading this know for sure?
I am not on my development machine right now, so I can't give an exact post of what my code looks like right now - if posting it would help debug, please let me know & I will repost.
Yeah, that might help.
Feb 21 '07 #5
karlr
5 New Member
Thanks again for your feedback. From the examples I have downloaded, I know how to structure the SQL tables (the field names, types, etc), so I think I am OK there. I am just having a hard time "wiring up" my application to use the table that contains the profile information via ASP.NET.

Hopefully someone can direct me to a good example of how to do this.

P.S. It's impressive that you can code in notepad. I code in a pretty expensive version of VS2005, and my code still doesn't work. ;-)
Feb 21 '07 #6
karlr
5 New Member
As I mentioned earlier, this is what my web.config file looks like:

Expand|Select|Wrap|Line Numbers
  1.       <profile enabled="true" defaultProvider="MyProfileProvider" >
  2.         <providers>
  3.           <add name="MyProfileProvider" type="MyProfileProvider"
  4.               connectionStringName="Data Source=karlweb;Initial Catalog=WebReport;Persist Security Info=True;User ID=VbUser;Password=VbUser" providername="System.Data.SqlClient" />
  5.         </providers>
  6.         <properties>
  7.           <add name="Country" type="string"/>
  8.           <add name="Gender" type="string"/>
  9.           <add name="Age" type="Int32"/>
  10.         </properties>
  11.       </profile>
Maybe someone can tell me if this is valid. If so, I can start figuring out where in VB I am going wrong. Thank you.
Feb 21 '07 #7
jhardman
3,406 Recognized Expert Specialist
I feel like the answer is in the code that sends the query, not the web.config (but I could be wrong).

Try a really simple script to see if it pulls up the right data:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. dim connect, objRS, query
  3. set connect = server.createobject("ADODB.connection")
  4. connect.open "DSN=mydbDSN"
  5. set objRS = server.createobject("adodb.recordset")
  6. query = "SELECT * FROM [table1]"
  7. objRS.open query, connect, adopenstatic
  8. %>
  9. <table><tr>
  10.  
  11. <%
  12. dim fld
  13. for each fld in objRS.fields %>
  14.    <th><%=fld.name%></th>
  15. <%
  16. next %>
  17. </tr><tr>
  18. <%
  19. dim idnum
  20. do while not objRS.eof
  21.    for each fld in objRS.fields %>
  22.       <td valign="top"><%=fld.value%></td>
  23.     <%
  24.     next
  25.     response.write "</tr><tr>" & vbcrlf
  26.     objRS.movenext
  27. loop %>
  28.  
this should list every field in the table you ask for. Try it for both tables, and see if it pulls up your test data.
Feb 26 '07 #8
MannyZanny
2 New Member
I'm not sure if this is too late for but I was searching for the same thing and found a solution and remebered your post so I signed up to help you out.

First, I tried your web.config text and I got it show up in intellisense after saving everything and I did a build to get it to show up (CTRL+SHIFT+B) in VS2005. It was a little tricky to get intellisense to pop it up but I'm sure if you do a build it should fix things. I also wanted to let you know you can create a group of fields like this:

<group name="Address">
<add name="Street"/>
<add name="Country"/>
<add name="PostalCod e"/>
</group>

which will allow you to access fields like this: Address.Street = "Name" Address.Country = "Country"

Now to actually add this information you can create controls yourself and use this code:

Expand|Select|Wrap|Line Numbers
  1. ' Variable to retrieve the creating status
  2.         Dim status As MembershipCreateStatus = Nothing
  3.  
  4.         ' Create the user
  5.         Dim user As MembershipUser = Membership.CreateUser("Username", "Password", "Email", "Question", "Answer", True, status)
  6.  
  7.         ' Check for errors one way by seeing if the user is nothing
  8.         If user Is Nothing Then
  9.             ' Error creating user
  10.             lblMessage.Text = status.ToString
  11.  
  12.             Return
  13.         End If
  14.  
  15.         ' Also this way by seeing the status 
  16.         If status = MembershipCreateStatus.Success Then
  17.             ' Error creating user
  18.             lblMessage.Text = status.ToString
  19.  
  20.             Return
  21.         End If
  22.  
  23.         ' Retrieve the profile of the user added
  24.         Dim pc As ProfileCommon = Profile.GetProfile(user.UserName)
  25.  
  26.         ' Set our custom data and save
  27.         pc.FullName = "Manuel Marquez"
  28.         pc.DOB = Now.Date ' Haha
  29.         pc.Address.Street = "Street Name"
  30.         pc.Address.Country = "Canada"
  31.         pc.Address.PostalCode = "H0H0H0" ' Santa Claus
  32.  
  33.         ' Save our new data
  34.         pc.Save()
  35.  
  36.         ' Display some message
  37.         Me.lblMessage.Text = "User created successfully!"
of course replacing string fields with textboxes, date pickers ect.

However if you want to use the Create User Wizard I figured it out after a couple of hours because the controls are hard to get at, don't know why they don't show up under Me?

Here's what I did to get it working:

1. Add a create user wizard (mine is CreateUserWizar d1)
2. Click arrow in top right then select customize create user step
3. Add a new fields (FullName textbox)
4. Now you have to rename trhe step ID by clicking "Add/Remove Wizard steps". The first one should be create user.... and change the name of the ID (last property). I chose CreateUserWizar dStep1
5. Add code to the create wizard CreatingUser method

Expand|Select|Wrap|Line Numbers
  1. Protected Sub CreateUserWizard1_CreatingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser
  2.         ' Get the new user profile
  3.         Dim pc As ProfileCommon = Profile.GetProfile(Me.CreateUserWizard1.UserName)
  4.  
  5.         ' Get the textbox with the data in it being FullName textbox. The CreateUserStepContainer was where I found my control
  6.         Dim txt As TextBox = Me.CreateUserWizardStep1.FindControl("CreateUserStepContainer").FindControl("FullName")
  7.  
  8.         ' Set the field
  9.         pc.FullName = txt.Text
  10.  
  11.         ' Save the profile
  12.         pc.Save()
  13.     End Sub
Now when you add a user its created with all the extra fields added. If your wondering where I got CreateUserStepC ontainer I had to get all the controls and display the name narrowing my search until I found it using.

Expand|Select|Wrap|Line Numbers
  1. lblText.Text = ""
  2.             For Each ctl As Control In Me.CreateUserWizardStep1.Controls
  3.                 lblText.Text &= ctl.ID
  4.             Next
Like I said the hard part is getting the controls in order to get the entered data. This should solve your problem but be aware that the data will not go into a table nicely because the extra fields are actually saved as follows in the table aspnet_Profile:

Property Name Field: FullName:S:0:14 :Address.Street :S:14:9:Address .Country:S:23:6 :Address.Postal Code:S:29:7:DOB :S:36:87:

Property Value Field: Manuel MarquezStreetNa meCanadaH0H0H0< ?xml version="1.0" encoding="utf-16"?>
<dateTime>200 7-03-06T00:00:00-05:00</dateTime>


So if you want to display the data in a table you will have to load the profile data into a dataset manually or something. You will also find other useful methods in Membership like DeleteUser which you should be able to figure out how to use by intellisense. WOW thats a lot of information and I discovered a lot to do something simple, hope it helps you out.
Mar 7 '07 #9
karlr
5 New Member
MannyZanny,

Thanks a lot for researching & testing this for me! I have a couple of questions about how you did this.

Did you use a ASP.NET Web APPLICATION or a Web SITE? I have found that when I create a brand new ASP.NET Web Site, the intellisense for the added profile properties works properly, but if I do the exact same thing in a web Application, it does not.

Also, when I aded your VB code, I ran into an issue I saw earlier. That is, VS says that for this line:
Dim pc As ProfileCommon = Profile.GetProf ile(user.UserNa me)

"Type 'ProfileCommon' is not defined". Did you have to add a reference or something else to get this to work? I tried using what VS suggested as fixes ('ProfileModule ' & 'ProfileInfo') and got errors downstream.

Lastly, would you be willing to e-mail me your test project? Even if it is "broken" because I don't have the same database objects, I think it might be valuable to me. In any case, I will continue to test further with the methods you have kindly shown.

Again, thank you very much for your reply.
Mar 7 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1985
by: | last post by:
Hi all, How can I get a reference to my custom profile provider in my .aspx page? I have looked at httpcontext.current.profile. But from there where do I go? Ideally I would like to be able to get default profile provider without having to know the "name" configured in web.config. TIA!
2
4270
by: John | last post by:
Hi I am trying to setup a customised membership provider and I am getting the following error when trying to run the app; The entry 'AspNetSqlMembershipProvider' has already been added. The line is: <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
4
2249
by: techsupport | last post by:
I have some experience with .NET Remoting, as well as ASP.NET 2.0, and have been wanting to remote a custom membership and profile provider. I want to take advantage of the new controls in ASP.NET 2.0 such as Login, Loginuser, Loginview, etc. The ASP.NET provider model requires entries in the web.config for a 'connectionStringName', which I understand is utilized to connect to the data source. Problem is the client machine (machine A)...
0
1690
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a specified date. - DeleteProfile. Enables you to delete a profile associated with a specified username. - DeleteProfiles. Enables you to delete a set of profiles. - FindInactiveProfilesByUserName. Returns a collection of ProfileInfo
0
1163
by: Phil | last post by:
I created a custom profile provider based on the example here : http://www.theserverside.net/articles/showarticle.tss?id=CreatingProfileProvider It works ok, but when I try to get the last update date/time for the profile using Profile.LastUpdatedDate I receive the following error. Invalid column name 'PropertyNames'. Invalid column name 'PropertyValuesString'. Invalid column name 'PropertyValuesBinary'.
3
1922
by: Rich Armstrong | last post by:
I've implemented a custom profile provider following the pattern and examples provided with ASP.NET 2.0, but no Profile object ever appears in my page; that is, after executing the following, ProfileCommon profile = this.Profile; in my Page_Load method, profile is always null. My web.config file contains the following section:
0
1432
by: Rajesh | last post by:
I am trying to use a simple custom type for saving the profile information of a user. The custom class inherits from the Hashtable. I am serializing the type as "Binary" in the provider sections of the web.config. When I add a key-value to the custom type, I can see that its being saved in the database (aspnet_profiles table - PropertyValuesBinary column). But, when I want to read the information in the profile, my custom type object is...
9
3282
by: Kirk | last post by:
I have successfully, implemented a custom Membership Provider to a SQL 2000 table, however, I am having problems doing the same with a Profile Provider. As I understand it, the steps for both of these are similar: Create a new class (MyMembershipProvider and MyProfileProvider). Add the "Inherits..." value to the provider (MembershipProvider and ProfileProvider). Modify the web.config file to assign this class and it's connection...
2
1567
by: Kees de Winter | last post by:
Hi, I am thinking about using the personalization features of .net 2.0 but I can't figure out the following. If I use the standard features of personalization, I will have users in the auto-generated profile-tables. But I have my own user tables with many more fields. How do I sync these users with the profile tables? I have thousands of users in my tables but if I can't use these tables for personalization it seems quite useless... ...
0
9709
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10936
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10609
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7853
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7025
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5695
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.