How to store user profile information during create user?

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
GuyBCool
2/18/2006 2:01:19 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

9 Replies
748 Views

Similar Articles

[PageSpeed] 9

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
pkellner
2/19/2006 1:05:50 AM
Thanks pkellner,

Do u have VB Code?
0
GuyBCool
2/20/2006 10:30:22 AM

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
Mark
3/12/2006 11:01:45 AM

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
pkellner
3/12/2006 3:35:13 PM

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
ANik
11/9/2007 12:45:26 PM

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
naturehermit
11/9/2007 12:59:14 PM
Btw, was unable to see anything about rolling back in
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/profile/default.aspx
0
ANik
11/9/2007 1:10:17 PM

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
naturehermit
11/9/2007 1:36:25 PM
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
ANik
11/9/2007 1:44:29 PM
Reply:

Similar Artilces:

Modify User Information / User Profile
I have been rooting around looking for the answer... with no luck... I want to modify the User Information / User Profile collected, for example delete MSN, AIM and Yahoo and add City, State and Zip. Where is this? Is it right in front of my nose? Thanks in advance, (again). The table in the DB is the Community_Users table. You will have to either extend this table, or create a new table using a foreign key relationship to the users table to hold your new fields. You probably don't need to mod any stored proc though since the profile procedures use select * (bad design, but ...

Where is the user information stored once a new user is registered?
I have created the following stored procedure to find matching data in the CMRC_Customers table in the ECommerce Starter Kit, however, it does not find customer information that I use to logon. In fact, I have retrieved the CMRC_Customers result set, and newly registered user data does not appear in this table. I know that it is stored somewhere, because, when I sign in, it says welcome, with my name. Can anyone tell me where registered user information (FullName, EmailAddress, CustomerID) is stored? Thanks.... CREATE PROCEDURE MyProcedure @full_name nvarchar(50) @email_address nvarchar(...

Custom user information in Create User control
In my user registration form, I would like to have more fields like Company Name, Surname, Product S/N..etc.  Is it possible to do this using .NET 2.0 CreateUser Control?  If not, I should create my own form, right?  If I do this, how can I store information(username, password, email..etc) in the build-in aspnet_xxx tables as CreateUser control does? Thanks. Yes this is totally possible.  It is a little lengthy to just get into.  I can't type out a bunch of code right now, or even tonight.  I just read a chapter in this book a couple weeks ago that ...

E-mailing Create User & Profile info AND changing Create User Wizard defaults
Hi, I'm in the final countdown on my site, built with VWD 2005 X Ed and can't seem to find a consistent response to a couple of questions.  Maybe someone out there can help?  I am very, very new at .NET 2.0 and SQL Server, so any detailed/example responses would be very appreciated.E-MAILING CUSTOMIZED CREATE USER WIZARD DATA There are dozens of complex tips here and elsewhere on how to customize the create user wizard then send the information to the Profile section or into a custom database.  While I don't exactly understand any of these posts yet, I'...

Manage Users
Hello, I would like to manage all available users with their custom profile datas, eg. firstname. I can get the profile datas of the logged-in user (VB code: txtBoxFirstName.Text = Profile.FirstName) but how can I list all the not-logged-in users with their usual datas (eg. e-mail address) and their profile datas? Thank you in advance   Because of performance issues I don't recommend you to use the Profile if you need to list all users’ properties on a single page. But if you only have a few users, then it's fine ;) To get the profile for all users you can for examp...

stored procedure to get all users or all users of a specific country
hi alli've got two tables called "webusers" (id, name, fk_country) and "countries" (id, name) at the meantime, i've a search-page where i can fill a form to search users. in the dropdown to select the country i included an option which is called "all countries". now the problem is: how can i make a stored procedure that makes a restriction to the fk_country depending on the submitted fk_country parameter?it should be something like SELECT * FROM webusers(if @fk_country > 0, which is the value for "all countries"){    WHERE ...

Storing data in a Custom table within ASPNETDB.mdf vs. storing information about a user in a profile
Don't know if the following question makes sense, nevertheless here goes... Which is better, Storing information about a user in a custom table within ASPNETDB.mdf or storing it in a profile to be placed on a user profile page. Should both be implemented or will one suffice?  Hi, SuperRom:Should both be implemented or will one suffice?One will be enough.In general , if you want to display those profile properties using external reporting tool like crystal reports or reporting services , you will not be able to do that.This is because the profile properties will be stored as a...

Single Users Profile and All Users Profiles List
I've made a discussion forum. And I have also installed simply asp.net membership. Now I want after click on user link to redirect to the page with User's info.I have simply user "John" and user "Bob" and everyone can click on those names and will see page with informations stored in Profile (Like Profile.Name, Profile.Address). I have three simply question:1. How to show profile values of other User ? Like I wrote above.2. How to list all users with for example their e-mails ? I mean: UserLogin - UserName - UserMail3. Or the easier way is to make new table with those all information an...

How can I carry anonymous users profile information to authenticated user
HelloI can carry the anonymous users profile information like favourite team name etc but when the user logs in how can I  carry the profile knowledge to the authenticated users profile.Good Nights Please provide some more information about the hangup. At least I couldn't understand what exactly are you trying to achieve. So simple... yet so effective.My "Life"ly Blog You need to add the Profile_MigrateAnonymous event in your global.asax. Here's a sample: void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e) { //Migrate Profile Profil...

Store and get cookies information by user??
In my report , i have 2 report type: Weekly and Monthly.  if the user login next time, i want to disply the selection which lastly selectly by the user accordingly. If the user1 select Weekly then next time i want to display weekly option.  if the user5 select monthly then next time i want to display monthly for that userI am new to cookies.  please give me better/faster solution.  Thanks in advacne Here is an example of adding a cookie in C#string ReportType = "Weekly";HttpCookie Cookie = new HttpCookie("ReportType", ReportType );Cookie.Expires = DateTime.Now.AddY...

How can I get the user login ID by user Profile.FullName
I have a multiple user fullname list in a page(the fullname is stored in Profile). I need to save the user LoginID into the database when I select the user fullname.How can I get the user login ID by user Profile.FullName?Thanks. I get the answer: 1.get all user 2. create profile3. get the fullname to compare and get the IDCheers*  Hi,As per my understanding you have Key = Value pair where Key =  FullName and Value=LoginID. What i would suggest that you store this key value pair in Profile using HttpContext.Current.Profile.SetPropertyValue(FULLNAME,LOGINID); [Put it once in...

Creating addition profile information for users.
So here is my current issue.I have a user register on the register page in the root directory.  This is done with the create user wizard.  It works fine and creates ApplicationId, UserId, UserName, ect... in the aspnet_Users (dbo).  Then the user can edit / view their profile via the included attached pages that sit in the protected member directory.  This also works (somewhat).The problem is that the asp.net profile provider blobs the fields together in the aspnet_Profile(dbo) table.By doing this I can't query or run stored procedures against the database which is a ...

Getting / Editing a users profile information
    I have been trying to take advantage of the net User / Profile model in ASP.NET 2.0, and I can't figure out how to create an admin page and change the user's profile.I need to figure out how to get and change a user's profile from code.  None of the articles that I have run across talk about this.  Does anyone know of a good article on creating an adminstrator profile edit page?Thanks.AJAX Programming Tutorials It's pretty straightforward. Let's say you have a Profile property defined in your web.config called "WebsiteURL". To set the property you would do some...

How to save user information during create user in Custom Membership Provider?
 HelloSo i Inherits the  System.Web.Security.MembershipProvider, and i got a lot of  methods and propertys. one of them is CreateUser1 Public Overrides Function CreateUser(ByVal username As String, ByVal password As String, ByVal email As String, ByVal passwordQuestion As String, ByVal passwordAnswer As String, ByVal isApproved As Boolean, ByVal providerUserKey As Object, ByRef status As System.Web.Security.MembershipCreateStatus) As System.Web.Security.MembershipUser2 3 4 Dim ConnString As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|D...

Web resources about - How to store user profile information during create user? - asp.net.getting-started

Information - Wikipedia, the free encyclopedia
Information (shortened as info or info. ) is that which informs, i.e. an answer to a question, as well as that from which knowledge and data ...

InformationWeek – Latest Information Technology (IT) news & IT articles - Technology news - IT magazine ...
InformationWeek provides latest Information technology (IT) news online & articles and publishes latest tech news & IT magazine for Indian IT ...

ACT anti-domestic violence boss calls for better information sharing across sector
... ACT government will seek to strike a balance between victim safety with privacy concerns as it eyes better ways of sharing information ...

Queensland weather: Latest storm warning information
PARTS of Queensland were hit by severe storms, with golf-ball-size hail in the Granite Belt Monday afternoon.

Magnetic protein may provide animals with navigation information
What do monarch butterflies, salmon, lobsters, bats, mole rats, and marine nudibranch mollusks have in common? As I'm sure you already knew, ...

Security researchers have discovered more information on how the Sony hackers managed to stay undetected ...
More details of the hack that wiped out Sony Pictures' computer systems and resulted in thousands of internal emails and documents leaking online ...

White House offers states more information on refugees
Governors are still clashing with the administration over whether to admit Syrian refugees into their states

VTech hack exposes personal information of 5 million adults and children
Another data breach? Won't someone please think of the children?

Is The Freedom Of Information Act Stifling Intellectual Freedom?
The time to be surprised about FOIA requests is over: Scientists need to be on their guard and harness this digital world for themselves.

THE NUMBER GROWS Nearly 1,000 Clinton emails had classified information
THE NUMBER GROWS Nearly 1,000 Clinton emails had classified information

Resources last updated: 12/6/2015 10:48:23 PM