Hi,
I'm just try to store user information during create user via CreateUserWizard that add Textbox, DropDownList and RadoButtonList. How to store data form control to UserProfile (via CreateUserWizard) ?
Note. I set DisableCreatedUser = true because want to proof user befor activate.
(Begining ASP.net V2.0, VB, VWD 2005 Express Edition)
![]() |
0 |
![]() |
Here is some example c# code that I have in the CreateUser event of the CreateWizard command. I also do some stuff after this but I think this is the code you are interested in.
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
p.FirstName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxFirstName")).Text;
p.LastName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxLastName")).Text;
p.City = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxCity")).Text;
p.State = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxState")).Text;
p.Country = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxCountry")).Text;
p.Company = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxCompany")).Text;
p.Save();
Peter Kellner
http://73rdstreet.com and blogging at
http://PeterKellner.net
MVP, ASP.NET
![]() |
0 |
![]() |
Thanks pkellner,
Do u have VB Code?
![]() |
0 |
![]() |
Thanks for this pkellner.
I suppose that this solution stores the 'extra' information (i.e. info that is not stored by the default implementation:
MembershipProvider.CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
, that is FirstName, LastName, City, State, Country, Company) in a separate database table, and links the two tables using the candidate key "UserName". Is that correct?
If yes then what happens if an error is thown in p.Save() which results in, say, the extra information not being saved to the database? Are you able to roll back the base user information that MembershipProvider.CreateUser added?
If you have rollback code, then please could you post it? That would be a great help.
Thanks in advance.
![]() |
0 |
![]() |
I don't know of any way to roll the data on error. I think you would have to write your own provider for that. BTW, I would link the tables with ProviderUserKey but probably username is just as good since usernames don't duplicate. Something about a Guid just makes me feel better.
I think that you might want a routine that loaded all users (getallusers()) and got rid of entries in your extra table that were orphaned. Especially if you are using username as the foreign key or you might get surprise info attached to new users that were half added or deleted.
As an aside, I've completed work on a tool to generate an ObjectDataSource out of no only basic membership info but also the profile properties. Send me on a note on my blog (http://peterkellner.net/contact) if you are interested and I'll send you the link.
-Peter
Peter Kellner
http://73rdstreet.com and blogging at
http://PeterKellner.net
MVP, ASP.NET
![]() |
0 |
![]() |
Mark is right. Although custom membership provider is a good idea, but it's still raw... :(
Let's say, we have 'users' table, that contains obligatory fields not represented in 'microsoft users table'.
Splitting such info into 2 tables (1:1) won't go, because it's impossible (as far as i can see) to implement transaction for filling these 2 tables ('CreateUser' method call is hidden) and all in all - such structure looks clumsy...Maybe theoretically it's possible to create additional corresponding fields in custom membership provider class and initialize them in 'CreatingUser' method, then take them for inserting new record in 'CreateUser'? But such approach also looks ugly... :(
Creating own membership provider from scratch is a headache, especially for beginners (you have to deal with multithreading, preventing access to membership while initialize method works).
I wonder why Microsoft just hadn't created one more abstraction layer for the structure of 'users' table? So instead of having 'CreateUser(param1, param2, ... paramN)' we could have something like 'CreateUser(UserStruct user)'....
![]() |
0 |
![]() |
Mark Davies:
Thanks for this pkellner.
I suppose that this solution stores the 'extra' information (i.e. info that is not stored by the default implementation:
MembershipProvider.CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
, that is FirstName, LastName, City, State, Country, Company) in a separate database table, and links the two tables using the candidate key "UserName". Is that correct?
If yes then what happens if an error is thown in p.Save() which results in, say, the extra information not being saved to the database? Are you able to roll back the base user information that MembershipProvider.CreateUser added?
If you have rollback code, then please could you post it? That would be a great help.
Thanks in advance.
A profile table is a different table and its all stored as a flat table, and the link is established on the fly without requiring user intervention as long as these are declared in web.config. Read this article for an understanding http://www.odetocode.com/Articles/440.aspx
And for the rollback stuff read this article http://quickstarts.asp.net/QuickStartv20/aspnet/doc/profile/default.aspx
GuyBCool:
Thanks pkellner,
Do u have VB Code?Here's the code in Vb.net
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
Dim p As ProfileCommon = DirectCast(ProfileCommon.Create(CreateUserWizard1.UserName, True), ProfileCommon)
p.FirstName = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxFirstName"), TextBox).Text
p.LastName = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxLastName"), TextBox).Text
p.City = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxCity"), TextBox).Text
p.State = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxState"), TextBox).Text
p.Country = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxCountry"), TextBox).Text
p.Company = DirectCast(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TextBoxCompany"), TextBox).Text
p.Save()
End Sub
Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
![]() |
0 |
![]() |
Btw, was unable to see anything about rolling back in http://quickstarts.asp.net/QuickStartv20/aspnet/doc/profile/default.aspx
![]() |
0 |
![]() |
In the sample I meant to discuss the profileManager class which can be used to clear up the profile data (not as in database rollback.
The ProfileManager class can be used both within an ASP.NET page and outside of an ASP.NET page. For example, you might want to create a console application that automatically executes once a day and cleans up inactive profiles. For e.g. a console app in c# that does the job
using System; using System.Web.Profile; public class DeleteInactiveProfiles { public static void Main() { int deleted = 0; deleted = ProfileManager.DeleteInactiveProfiles( ProfileAuthenticationOption.All, DateTime.Now.AddDays(-7)); Console.WriteLine("Deleted " + deleted.ToString() + " profiles" ); } }
Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
![]() |
0 |
![]() |
Sorry, naturehermit. Btw, for one who could be interested. In google groups i've bumped into interesting idea: if you need to pass extraparameters to CreateUser method, you can use providerUserKey! It's 'object' tyoe - so it could contain any structure. Not very elegant, but definitely solves some limitations of 'profile' approach. Wow, I will try this now... :)
![]() |
0 |
![]() |