Adding custom fields on asp net membership users table - asp.net

I have a application which I would like to add custom fields to the users table. I am not sure how to work after adding the columns. The columns are foreign keys to another table which holds more details for the user.
I am using Linq-to-SQL. So every time I add a user (using the membership functions i.e. Membership.CreateUser(..)) I end up calling another service to update the foreign keys on the users table.
Any better way of doing this will be highly appreciated.

Why are you adding foreign keys to the User table, pointing to another table with additional info??
I would do it the other way around:
create your own table UserInfo
create a FK column in UserInfo that points to the row in your ASP.NET membership User table
leave the system-provided User table alone - so you won't run into problems when e.g. an upgrade to the ASP.NET membership system is rolled out.....

I strongly recommend you not to extend secure tables such like Users, Membership, Profile. Better create another one table in your database (not secure database) with full info which you need. Call it 'User' with foreign key to 'Id' of table User in secure database.

Related

To fill up asp.net membership

I believe I want to do a update query.
I've found a tutorial that introduces me to ASP.Net membership where I can use an Access provider to fill my database needs. However, I have an existing Access database of customers, but I do not know how to copy this existing database into the new ASPNetDB.mdb. It's identical to the SQL provider as far as I know.
Every table is related to each other so I cannot enter new records. I've wanted to append the UserName column, the passwords, email's, and a new field to the new ASPNetDB.mdb. How would I go about doing this?
So instead of having to copy records from one database to another database why don't you just create a custom membership provider and use the same existing database.
Basically you create a class that inherits from the MembershipProvider class and you implement all the methods from the MembershipProvider class. I.E. ChangePassword, CreateUser, DeleteUser, etc... In your implementation you write custom code to access the tables that already exist.
This way you can keep your current database and still use ASP.NET membership.
Here is an MSDN article with a sample implementation.
Sample Membership Implementation
As suggested, if the table structures ARE the same, then why not just make a copy of the original database and re-name to the same as your ASPNetDB.mdb.
If you're looking to import older data, then again simple open ASPNetDB.mdb with Access and import the data + tables from the older database. Access can and WILL import the tables and WILL ALSO BRING IN related data tables. This will create new local tables, but then again you stating they are the same. (so delete the existing tables in ASPNetDB and import the other ones).
You can ALSO import the table data into existing tables if they are empty. So assuming empty tables, then a compact + repair will re-set auto numbers, and then you can link to the older database and use append quires. I would only do this if a few tables. You have to import the "parent" tables first if referential integrity is enforced as it makes little sense to add child records first!
However I fail to see why not just making a whole copy of the older existing database and re-naming it as ASPNetDB would not work if your claim of the tables being the same in both.

aspnet_user table for storing customer information

When regsitering in my site (ASP.Net MVC application), the users get inserted into the aspnet_users table. Since its a shopping site, I would want the users to have a customer id and all their details provided by them at registration in this Customer table as well. How do I link these 2 tables? Is it recommended to use the aspnet_user's UserId(Guid) in the application for other business processes.
Also, I would like to know when should a new record be inserted into the customers table.
I mean, when should a new customer be created. I guess its not good to create a record as ans when users are registered? Here, I want to know whats the norm? I felt it would be better to add it when a user adds an item to the shopping cart. Pls guide me.
Thanks in advance.
Add the UserId field into your customer table and then make a foreign key relationship back to the UserId in the aspnet_users table if you want to enforce relational integrity.
I'm not sure what you mean about when to insert the customer record. As long as you insert it after you have created the user (so that you have the user ID), you should be fine. It can happen in the same postback.
I'm not sure how you are saving the user. As in are you using one of the built-in ASP.Net controls or making the call manually?
If you are using the Membership provider as it sounds like you are, you can save the member using:
var user = Membership.CreateUser;
Guid userKey = user.ProviderUserKey;
//Populate your customer object.
//now use whatever EF/ADO/etc... to save your customer record.

What is aspnet_Users and aspnet_Membership? Which one should I use? What is the difference?

I'm using default membership class in my website. But I'm a little confused with the complex database design of the ASPNETDB.
Let's say I want to add details about user like name, surname, address etc... Where should I put them aspnet_Membership table or aspnet_Users table and why? I mean I can see that I should put the details on aspnet_Membership. But then again why there is two of them and the bindings on aspnet_Users...
Or lets say I'm adding a messaging into that which table should I key to, for the user details?
I'm confused and I would be appreciated if you can tell me the use of these two tables.
Here is the diagram for the default ASPNETDB which you should probably have:
Rather than modifying the built in ASP.NET membership schema, you can use ASP.NET profiles to store custom properties about your users. Here's one tutorial on the subject.
You can add the profile tables to your schema using aspnet_regsql.exe (which you're probably already familiar with, given that you have already generated most of the schema). Use the -R p switch to get the profile tables/procs.
If you want to connect your custom table to ASP.NET membership, use UserId as foreign key from aspnet_Users table rather than aspnet_Membership table to your custom table. For reference, please note how aspnet_Profile or even aspnet_Membership is using UserId as foreign key from aspnet_Users table.
Please see the database diagram here:
http://msdn.microsoft.com/en-us/library/Aa478948.asp2prvdr0102l(l=en-us).gif
Good luck ...
I would advise not to alter any of the tables provided by the ASP.NET membership schema. To store additional data use the already mentioned ASP.NET profiles option or create a custom one which maybe fits your bill beter.
The reason why there are two tables for storing user data is already answered over here.
Good luck which choosing the right solution.

ASP.NET Membership - is this good design

I added asp.net membership in my web application. Now I have one table where I have columns for user specific information UserProfile(FirstName, Lastname, DisplayName etc.). I didn't use Profile from membership because if in the future I decide to change asp.net membership for something else I want to keep user personal data in separate table. My question is: I use UserId (unique identifier from asp_membership_users table) as a foreign key in my custom table. Is UserId smart choice to connect these tables?
Yes, it's the primary key of the asp_membership_users table so it makes sense to use it as the foreign key of your custom table.

Adding an integer ID to ASP.NET Forms Authentication

In the standard forms authentication, users are identified by a Guid. I want to give my users an UserId of type int (doesn't have to be the primary key, just something to do lookup's on).
Is it safe to add an additional column to the aspnet_users table, or should I create a new table which FKs to the UserId column and has a Unique column which generates the integer ID?
The later sounds like a bad performance hit to take just for the sake of an int!
EDIT
I want to create URLs like those on stackoverflow. eg. https://stackoverflow.com/users/23590/greg-b where the User ID is an int. For that reason I don't want to use Guids.
I'd create profiles and store the associated urlID there. Web Forms don't have Profiles available out of the box, but you can see a workaround here:
http://www.codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx
The advantage of using Profiles is that you can tap into all the existing logic and won't have to write as much custom code yourself, aside from constructing the URL.
You could combine this with Routing for friendly URLs, if you're using ASP.NET 3.5 or up.
UPDATE: kinda similar question:
Shorter GUID using CRC

Resources