How To implement custom data with Asp.net Membership feature

Last post 01-29-2009 11:45 AM by raghav_khunger. 9 replies.

Sort Posts:

  • How To implement custom data with Asp.net Membership feature

    01-27-2009, 12:14 AM
    • All-Star
      21,236 point All-Star
    • raghav_khunger
    • Member since 08-18-2008, 12:25 PM
    • Delhi, India
    • Posts 3,776
    • TrustedFriends-MVPs

     Hi,All


    I want to use Asp.net membership feature.In create User Wizard There I see that is only 5 to 6 options availaible.ie

    username,password,email,security question,answer

    I Have A create user wizard  form there are 10 to 20 controls extra ie others information I have to take and their values will be get stored in database .
    I am thinking of a structure that will have a master user tables and

    other tables linked to master with user id(primary -foreign key relation)


    BUt the main logic is how to add extra data that i am saying with asp.net membership feature
     

    Raghav CodeASP.NET Community | My Blog | jQuery Intellisense in Visual Studio 2008




    "Success doesn't come to you…you go to it."--Marva Collins

    "Failure is success if we learn from it." Malcolm Forbes

    "Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


  • Re: How To implement custom data with Asp.net Membership feature

    01-27-2009, 2:51 AM
    Answer
    • Contributor
      2,780 point Contributor
    • jpcoliveros
    • Member since 01-06-2006, 6:54 AM
    • Philippines
    • Posts 395
    • TrustedFriends-MVPs

    You can check on these links as this topic has been discussed before:

    http://forums.asp.net/t/1370557.aspx

    http://forums.asp.net/t/1362221.aspx

    http://forums.asp.net/t/1358992.aspx

     

    Patrick Oliveros
    superpatrick.wordpress.com
  • Re: How To implement custom data with Asp.net Membership feature

    01-27-2009, 2:16 PM
    Answer
    • All-Star
      18,842 point All-Star
    • guru_sarkar
    • Member since 08-31-2007, 12:00 AM
    • Posts 2,860

    Some similar logic here:

    http://aspnet.4guysfromrolla.com/articles/070506-1.aspx

    http://www.asp.net/learn/security/tutorial-08-vb.aspx

    In short:

    In the CreatedUser Event of CUW ... Get the controls' value and insert them into the other tables linked to master table via UserId.

    Sample code a bit modified from second link:

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)

    {

    // Get the UserId of the just-added user

    MembershipUser newUser = Membership.GetUser(CreateUserWizard1.UserName); Guid newUserId = (Guid)newUser.ProviderUserKey; //Get Profile Data Entered by user in CUW control

    String FirstName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;

    String LastName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("LastName")).Text;

    // Insert a new record into UserProfiles

    string connectionString = ConfigurationManager.ConnectionStrings["MembershipConnectionString"].ConnectionString;

    string insertSql = "INSERT INTO User_Profile(UserId,FirstName, LastName) VALUES(@UserId, @FirstName, @LastName)";

    using (SqlConnection myConnection = new SqlConnection(connectionString))

    {

    myConnection.Open();

    SqlCommand myCommand = new SqlCommand(insertSql, myConnection); myCommand.Parameters.AddWithValue("@UserId", newUserId);

    myCommand.Parameters.AddWithValue("@FirstName", FirstName);

    myCommand.Parameters.AddWithValue("@LastName", LastName);

    myCommand.ExecuteNonQuery();

    myConnection.Close();

    }

    }

    Here User_Profile is my profile table and UserId had FK relationship with aspnet_Users table.

  • Re: How To implement custom data with Asp.net Membership feature

    01-27-2009, 11:18 PM
    • All-Star
      21,236 point All-Star
    • raghav_khunger
    • Member since 08-18-2008, 12:25 PM
    • Delhi, India
    • Posts 3,776
    • TrustedFriends-MVPs

     Hi,

    Tell Me One Thing .

    That What is the solution for the case.

    Suppose I have already a table with three fields userNAme ,Password nand email means previously I was having these tables and other tables are linked though these UserId.

    I want to ask that now How to implement Asp.net membership feature with these data .

    I think I am asking A valid question because If a company already has present data and if he wants to implement asp.ne membership feature 

    then They cant afford to make their users to re register in them.

    Please Tell Me.

     

    Raghav CodeASP.NET Community | My Blog | jQuery Intellisense in Visual Studio 2008




    "Success doesn't come to you…you go to it."--Marva Collins

    "Failure is success if we learn from it." Malcolm Forbes

    "Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


  • Re: How To implement custom data with Asp.net Membership feature

    01-28-2009, 12:18 PM
    • All-Star
      18,842 point All-Star
    • guru_sarkar
    • Member since 08-31-2007, 12:00 AM
    • Posts 2,860

    Suppose I have already a table with three fields userNAme ,Password nand email means previously I was having these tables and other tables are linked though these UserId.

    So do you want to use Membership APIs only or the membership database schema as well.

    If you just want to use Membership APIs ...with your already existing tables you should look into 'Custom Membership Provides'. 

    If you also want to use membership tables, you will have to migrate your data from your table to membership tables. You might want to look into DTS with Sql Server.

    Or you can loop through the existing user table and pass the values to Membership.CreateUser(..) method to register them automatically instead of asking users to re-register. But this has some complications involved.

     

  • Re: How To implement custom data with Asp.net Membership feature

    01-28-2009, 12:25 PM
    • All-Star
      21,236 point All-Star
    • raghav_khunger
    • Member since 08-18-2008, 12:25 PM
    • Delhi, India
    • Posts 3,776
    • TrustedFriends-MVPs

     Hi,GUru

    Actually I want to avod seesions controlling for credintials.

    There for I want to imple ment that asp.net membership tables features that will automatically control my site 

    on behalf of security it has .That Is wahy I was Asking that How can I make my my tables Suppose 

    Mast_user Table That I ahve Specified abopve.

    DO u help me With some Code .

    Raghav CodeASP.NET Community | My Blog | jQuery Intellisense in Visual Studio 2008




    "Success doesn't come to you…you go to it."--Marva Collins

    "Failure is success if we learn from it." Malcolm Forbes

    "Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


  • Re: How To implement custom data with Asp.net Membership feature

    01-28-2009, 12:43 PM
    • All-Star
      18,842 point All-Star
    • guru_sarkar
    • Member since 08-31-2007, 12:00 AM
    • Posts 2,860

    Actually I want to avod seesions controlling for credintials. 

    There for I want to imple ment that asp.net membership tables features that will automatically control my site 

    on behalf of security it has .

    could you explain a bit on that.

    Also explain how are you authenticating now and what different behavior you are expecting when using membership providers.

  • Re: How To implement custom data with Asp.net Membership feature

    01-29-2009, 9:44 AM
    • All-Star
      21,236 point All-Star
    • raghav_khunger
    • Member since 08-18-2008, 12:25 PM
    • Delhi, India
    • Posts 3,776
    • TrustedFriends-MVPs

     Hi,

    I am ahving this doubt from many days how to implement that what i am saying.

     Currently I am using Session to store userid so that i can make  acces to particular page to that user on behalf of that id .I have A user table and others table linked to that user table with user id

    as foreign key relation ship Now that user table has userid,username,password,email column in it.I am saving the data in traditioal way as it is.

     

     Now i wan to make my same database structure so that i can make use of that asp.ne membershipfeature.Means In front end i will then be able to use Login contros etc provideed by Asp.net

     

     

    Actually i am not familiar wit that custom membership class that u r saying.

     

    So what wuld u say about my case............Confused

     

    Raghav CodeASP.NET Community | My Blog | jQuery Intellisense in Visual Studio 2008




    "Success doesn't come to you…you go to it."--Marva Collins

    "Failure is success if we learn from it." Malcolm Forbes

    "Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


  • Re: How To implement custom data with Asp.net Membership feature

    01-29-2009, 11:32 AM
    Answer
    • All-Star
      18,842 point All-Star
    • guru_sarkar
    • Member since 08-31-2007, 12:00 AM
    • Posts 2,860

    For custom membership provider check this: This will help you use your existing database in backend and login controls in front-end.

    http://support.microsoft.com/default.aspx/kb/910440

    http://www.asp.net/learn/videos/video-189.aspx

    Membership provider makes a database call to get the userId by passing the username.

    so if you have unique username, you can also write your own function that can retrieve userId from database ..passing username as parameter.

    You can obtain the username of logged-in user from Current HttpContext.

     

  • Re: How To implement custom data with Asp.net Membership feature

    01-29-2009, 11:45 AM
    • All-Star
      21,236 point All-Star
    • raghav_khunger
    • Member since 08-18-2008, 12:25 PM
    • Delhi, India
    • Posts 3,776
    • TrustedFriends-MVPs

     Hi,Guru

    Thanks for supporting 

     

    guru_sarkar:
    so if you have unique username
     

    Ya I have UserName Column Unique 

     

    guru_sarkar:
    For custom membership provider check this: This will help you use your existing database in backend and login controls in front-end.
     

    Really .............. can  i do that  Big Smile

    It will be awsome If I could get that successfull .

    Thanks So much I wll let u know After implementing that If I face Any thing Than I hope u will support in future.....

    Raghav CodeASP.NET Community | My Blog | jQuery Intellisense in Visual Studio 2008




    "Success doesn't come to you…you go to it."--Marva Collins

    "Failure is success if we learn from it." Malcolm Forbes

    "Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


Page 1 of 1 (10 items)