I want to design a new webform site using the SimpleMembership with C# and 4.5 framework. When I created the new site, it automatically created the tables "Users, Membership, Profile" and a few others. Now I want to add several additional colums/fields
to the registration page and also make a "profile" page.
1. Which table should I add all the additional colums to?
2. Do I need to use sql update statements to get the data into the additional colums, or is there a way to link it up using the SimpleMembership?
I want to design a new webform site using the SimpleMembership with C# and 4.5 framework. When I created the new site, it automatically created the tables "Users, Membership, Profile" and a few others. Now I want to add several additional colums/fields
to the registration page and also make a "profile" page.
1. Which table should I add all the additional colums to?
2. Do I need to use sql update statements to get the data into the additional colums, or is there a way to link it up using the SimpleMembership?
The new SimpleMembership model allows your "users" table to be whatever table you want. You just need username and ID columns. You can have any number of additional columns.You register your users table with SimpleMembership by invoking WebSecurity.InitializeDatabaseConnection
and passing the info if needs (DB connection, user table name, and column names).
When creating a user you can pass an object whose properties map to those custom columns. So for example:
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { ColumnA = "some value", ColumnB = 5, ColumnC = "some other value" })
Thank you for this. Now I do understand it is the Users table that I would modify. Can you tell me where/how I put the code "WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { ColumnA = "some value", ColumnB = 5, ColumnC = "some other
value" })"?
Thank you for this. Now I do understand it is the Users table that I would modify. Can you tell me where/how I put the code "WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { ColumnA = "some value", ColumnB = 5, ColumnC = "some other
value" })"?
Does it go in the web.config or another file?
No, this is the line of code when the user registers an account with your website. If you create a new MVC project in VS2012 you'll see this call in the generated AccountController code.
Sure -- I don't think the new WebForms templates auto-gen all the code that they do for MVC, but it'd be instructuve for you to look at it anyway (and run it to see how it behaves). Anyway, you can use all the APIs from WebSecurity (and thus SimpleMembership)
from WebForms -- you just have to write the code :)
Yes. I used the "Web Form Template" that is in VS2012. It created all the pages for me, using regualr web forms in aspx and aspx.cs. By default it uses the Simple Membership, but there is no code in the files. It must be built in to the framework somehow.
DotNet-Step1
Member
103 Points
158 Posts
VS2012 SimpleMembership Modification
Sep 04, 2012 01:30 AM|LINK
I want to design a new webform site using the SimpleMembership with C# and 4.5 framework. When I created the new site, it automatically created the tables "Users, Membership, Profile" and a few others. Now I want to add several additional colums/fields to the registration page and also make a "profile" page.
1. Which table should I add all the additional colums to?
2. Do I need to use sql update statements to get the data into the additional colums, or is there a way to link it up using the SimpleMembership?
Thanks for all the help.
DotNet-Step1
Member
103 Points
158 Posts
Re: VS2012 SimpleMembership Modification
Sep 04, 2012 10:04 PM|LINK
Bump...
All the examples I have found state to add the addtional columns to the "Users" table. But, all the examples are in WebMatrixs.
Can anyone answer how to do this in WebForm C# pages? Thanks.
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: VS2012 SimpleMembership Modification
Sep 04, 2012 10:30 PM|LINK
The new SimpleMembership model allows your "users" table to be whatever table you want. You just need username and ID columns. You can have any number of additional columns.You register your users table with SimpleMembership by invoking WebSecurity.InitializeDatabaseConnection and passing the info if needs (DB connection, user table name, and column names).
When creating a user you can pass an object whose properties map to those custom columns. So for example:
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { ColumnA = "some value", ColumnB = 5, ColumnC = "some other value" })
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
DotNet-Step1
Member
103 Points
158 Posts
Re: VS2012 SimpleMembership Modification
Sep 04, 2012 10:39 PM|LINK
Thank you for this. Now I do understand it is the Users table that I would modify. Can you tell me where/how I put the code "WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { ColumnA = "some value", ColumnB = 5, ColumnC = "some other value" })"?
Does it go in the web.config or another file?
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: VS2012 SimpleMembership Modification
Sep 04, 2012 11:25 PM|LINK
No, this is the line of code when the user registers an account with your website. If you create a new MVC project in VS2012 you'll see this call in the generated AccountController code.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
DotNet-Step1
Member
103 Points
158 Posts
Re: VS2012 SimpleMembership Modification
Sep 04, 2012 11:32 PM|LINK
This might me my problem. I'm not using MVC project. I created a Web Forms site. Will this still work?
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: VS2012 SimpleMembership Modification
Sep 04, 2012 11:40 PM|LINK
Sure -- I don't think the new WebForms templates auto-gen all the code that they do for MVC, but it'd be instructuve for you to look at it anyway (and run it to see how it behaves). Anyway, you can use all the APIs from WebSecurity (and thus SimpleMembership) from WebForms -- you just have to write the code :)
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
DotNet-Step1
Member
103 Points
158 Posts
Re: VS2012 SimpleMembership Modification
Sep 05, 2012 12:04 AM|LINK
Thats the part that got me started with this thread... I don't know how to write the code for the Web Form...
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: VS2012 SimpleMembership Modification
Sep 05, 2012 12:42 AM|LINK
Do you already have an application that allows user to register, login, logout, update account, etc?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
DotNet-Step1
Member
103 Points
158 Posts
Re: VS2012 SimpleMembership Modification
Sep 05, 2012 03:58 AM|LINK
Yes. I used the "Web Form Template" that is in VS2012. It created all the pages for me, using regualr web forms in aspx and aspx.cs. By default it uses the Simple Membership, but there is no code in the files. It must be built in to the framework somehow.