Advertisement

04.20.2008 at 02:01AM PDT, ID: 23337502
[x]
Attachment Details

How to create ASP.Net Membership Users & Profiles in a console app?

Asked by uswebpro9 in .NET Framework 2.0, C# Programming Language, Web Servers

Tags: C#

Hello,
I'm trying to create 5000 users in my application. I imported all the user data into my database. And used SubSonic to create a class/objects from it.

Can you create users and update thier profiles in a concol app? Below is the code I wrote. I'm getting errors:

Error      15      The type or namespace name 'Profile' could not be found (are you missing a using directive or an assembly reference?)      
Error      16      The type or namespace name 'GetProfile' does not exist in the namespace 'System.Web.Profile' (are you missing an assembly reference?)      

FYI: My app.config has the connections,membership, and role providers.

Thanks for your help!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Profile;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using SubSonic;
using SubSonic.Sugar;
using HVT.Common.Objects;
using HVT.Common.BusinessLogic;
using HVT.Common.Util;
using System.Web.Mail;
using System.Net;
using System.IO;
 
 
namespace ConsoleAppMigrate
{
    class Program
    {
        static void Main(string[] args)
        {
            MirgrateCustomerCollection cdata = new MirgrateCustomerCollection().Load();
            foreach (MirgrateCustomer cust in cdata)
            {
                // Create new user
                MembershipCreateStatus status;
                string question = "What is your favorite color";
                string answer = "Blue";
                bool isApproved = true;
                Membership.CreateUser(cust.EmailAddress, cust.Password, cust.EmailAddress, question, answer, isApproved, out status);
 
                if (status == MembershipCreateStatus.Success)
                {
                    //Add user to the Customer role
                    Roles.AddUserToRole(cust.EmailAddress, "Customer");
                    MembershipUser myObject = Membership.GetUser(cust.EmailAddress);
                    // New User Created. 
                    
                    // Get Their Profile
                    Profile newProfile = System.Web.Profile.GetProfile(myObject.UserName);
                    //  Update Their Profile
                    newProfile.Address = cust.StreetAddress;
                    newProfile.City = cust.City;
                    newProfile.Country = cust.Country;
                    newProfile.Email = cust.EmailAddress;
                    newProfile.FirstName = cust.FirstName;
                    newProfile.LastName = cust.LastName;
                    newProfile.Phone = cust.Phone;
                    newProfile.PostalCode = cust.ZipCode;
                    newProfile.State = cust.State;
                    newProfile.Save();
                }
            }
        }
    }
}
[+][-]04.20.2008 at 02:43AM PDT, ID: 21395492

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 02:46AM PDT, ID: 21395497

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 05:15AM PDT, ID: 21395806

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 10:22AM PDT, ID: 21396825

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 10:22AM PDT, ID: 21396829

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 03:06AM PDT, ID: 21399979

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.23.2008 at 12:27PM PDT, ID: 21424393

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET Framework 2.0, C# Programming Language, Web Servers
Tags: C#
Sign Up Now!
Solution Provided By: uswebpro9
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628