2

How can I add a user to the asp_Users table in my LightSwitch application with non-forms based authentication?

I have an application with forms authentication, and I need another one without any authentication for registration.

I have set up the same application name for both sites.

Application type:
Client>Web
Server>IIS

If I have both applications with forms authentication everything works OK with this code:

Application.Current.User.AddPermissions(Permissions.SecurityAdministration);
var NewUser = this.DataWorkspace.SecurityData.UserRegistrations.AddNew();
NewUser.UserName = "XXXX";
NewUser.FullName = "XXXX XXXX";
NewUser.Password = "*********";
this.DataWorkspace.SecurityData.SaveChanges();

var UserRole = (from role in this.DataWorkspace.SecurityData.Roles
                                where role.Name == "Customer"
                                select role).FirstOrDefault();

if (UserRole != null)
 {
    var newRA = this.DataWorkspace.SecurityData.RoleAssignments.AddNew();
    newRA.Role = UserRole;
    newRA.User = NewUser;
    this.DataWorkspace.SecurityData.SaveChanges();
}
Gayot Fow
  • 8,710
  • 1
  • 35
  • 48
tonco
  • 1,281
  • 3
  • 16
  • 30

1 Answers1

0

Setup a command that directly executes the aspnet_Membership_CreateUser stored procedure on the database, obviously passing the required values for all the parameters the stored proc expects.

Shawn de Wet
  • 5,642
  • 6
  • 57
  • 88