Authenticate user and create profile if not exist.

May 21, 2008 at 9:14 PM
I have a membership login as my first page, therefore I need a way to add a user to the portal only if they do not exist and remove anonymous portal viewing.  Any tips would be greatly appreicated.
May 22, 2008 at 4:49 PM
I too have an existing membership database with existing accounts and was able to tie into my database without any issues. 
I created the dashboard specific tables (widgets, widget_instance, etc.) from the dashboard db in my  aspnetdb database that contained the existing membership accounts.
Then point the web.config to my database.   Also in databaseHelper.cs, change the applicationId to match your applicationID:

public const string ApplicationID = "fd639154-299a-4a9d-b273-69dc28eb6388";  <-- change to your application id (you can get this from browsing the Membership table)

Then in Default.aspx  I added the following in the OnInit   just after  base.OnInit(e); :
        if (!Page.Request.IsAuthenticated)
        {
            Response.Redirect("~/Login.aspx");
        }

Also in web.config change all occurances of applicationName="Dashboard"  to applicationName="Your application name"



May 22, 2008 at 10:03 PM
Thank for the oninit tip.  I got the system changed over to my system name.  When a user logs into the system and the default page is activated an error occurs because there are no pages setup for the user so how do you handle this problem?  Do you know the call I need to check if pages exists?  I did find the "addnewpage" method and added this to the membership loggedin method so this works and the error does not show up, but it adds a page every time which is wrong.  Thanks in advance.

 

May 23, 2008 at 5:02 PM
Edited May 24, 2008 at 12:24 AM
Ok, here's what I did to resolve the same issue shown above...

My original website has a fairly big profile.  I replaced the profile code with my profile properties in web.config.  I added IsFirstVisit to my profile.

Then, in LoginPage.aspx.cs, in the login button click method I have:

if (Membership.ValidateUser(Email.Text, Password.Text)) {
  if (Profile.IsFirstVisit) {
    new DashboardFacade(Email.Text).NewUserVisit();
  }
  FormsAuthentication.RedirectFromLoginPage(Email.Text, false);  // I don't use the remeber
} else {
  InvalidLoginLabel.Visible = true;
}

THis creates teh necessary default pages.  Then in default.aspx.cs, under LoadUserPageSetup, I have

If (Profile.IsFirstVisit) {
 Profile.IsFirstVist = false;
  Profile.Save();
}

_Setup = new DashboardFacade(Profile.UserName).LoadUserSEtup();
Cache[Profile.UserName] = _Setup;
}


Works for all of my current membership logins and I have people register external to this site and works great.
}

 

Jun 26, 2008 at 6:05 PM
Thank you sir.