Extending User information inside asp.net mvc 5 project - asp.net

I have created a new asp.net MVC-5 web application , and I define individual user accounts as the authentication type.
Now when users register a new account they can enter email and password. Now I want to extend the users information when registering their account as follow:-
First name
Last name
Data of birth
Country
City
Address
Etc…
Now I am not sure what is the recommended way to extend the user info. Now I am trying to do the following 2 steps, as when the project was created a new database has been created automatically and it has a table named “ASPNETUSers”, which store the users info.
So I am thinking of adding the additional fields inside this table.
Then to modiy the “Account >> Register” view to render the additional fields.
So can anyone advice if my above 2 steps to store additional info about the users upon registration is valid ?or I should not modify the built-in database tables which include the ASPNETUSers ??

Related

Hardcode a role (outside database) for ASP.NET MVC and adding a Windows Authenticated Users

How would I go about hardcoding a role in ASP.NET MVC within the program itself, rather than through a database, for authentication (and then how could I add people to this role)?
What I'm trying to do is have 3 roles: Progammer, DatabaseAdministrator, and SystemsAdministrator. I'd like to be able to add people to those roles (also hardcoded), and then authenticate people based on role, rather than username. Right now, I am authenticating people like this:
If (#User.Identity.Name == "DOMAIN\\first.m.last")
What I want to be able to do is:
If (#User.Identity.Role == "ROLENAME")
However, I only have three roles and 8 people; I do not want to have to create a table in my database for them. So I'd create the role DatabaseAdministrator, and then add three people into as the string "DOMAIN\first.m.last". Then, I could have the action populate the view based on their rolename.
Everything I've seen so far has you do it through the database. Would appreciate any help. Thanks!
I am assuming that you are using Windows Authentication.
With that said you can easily authorize based on the users Active Directory Groups. This will keep you out of the database and all you have to do is add a user to an AD group if the users change.
Then you can authorize on the controller or action with this annotation.
[Authorize(Roles = #"DOMAIN\ADGroup")]

Add custom data to IdentityUser in MVC 5

I have been reading tutorial articles for a few days now, and most of the tutorials show either how to create login with IdentityUser class and Facebook, Google etc.(but no additional user data) or how to create user with their details without authentication.
My goal is to create application where a user can:
Login with Facebook(done)
Add personal data after that
Link personal data with the User entry in the default database that is created from ASP.NET
My question is:
Should I write a standalone controller and link it to the created user and how it is done?
Or should I add the additional data to ApplicationUser class?
I will be happy if someone share a good resource on that topic.
A standalone class linked to the Application user should be the best solution.
You should create a table with the structure: USERID, DATA1,DATA2....

ASP.NET MVC with multiple user tables and roles

I have an application that uses a client table, a company user table and an admin user table to manage companies. Companies have an admin area where they manage their users with roles of what their users can do, and a level above that the admin manages users that have their roles for managing all companies.
The question is: I want to use asp.net identity with authorize and roles in the appropriate controllers. Is there a way to integrate the existing user tables and roles for all three levels of users?
you can create a referrence table with many to many relationship to the asp.net users table like the below:
1- ASP.NET Users (The one Identity provider will give you)
2- Custom Table called (CompanyUsers) that takes the company ID and User ID
3- all tables linked to the above custom table

How to track and load a specific user's information?

I'm making a small portal in ASP.net (with C#.net4) where users can login and add, edit their personal information (PI). But I don't get how to load information (stored in a SQL server DB) in the page when a specific user is logged in.
For example: If Sam is logged in, he can view his PI. When Vicky is logged in, she can view her PI.
who can help me with this?
thanks in advance.
You need to retain the ID of the logged in user in a session variable and then use it to filter the query with which you fetch each user's info.
So if a user's ID is 278 then your query would run as:
SELECT first_name, last_name, * FROM user_table WHERE user_id = 278
From a session variable stored like:
Session["UserId"] = currentUserId;
The ASP.NET membership provider has already taken care of this for you. Have you considered using it? You can manage all of your authentication, permissions, roles, and access/edit profile information -- which you define. You access the data via the membership objects, and you won't need to write a single line of SQL to do it. It will save you loads of work instead of trying to reinvent the wheel.
Use the regular membership as described in the other answers. Then leverage the Profile system so that each user can view/edit their info when logged in (per the question). CAVEAT: ASP.NET profile system only works out of the box with the Website project template. If you want to use the Web Application project template, then follow the steps here:
ASP.NET: Web Site versus Web Application Project
When you have the profiles up and running, the profile data can be stored in session objects while the user is logged in.

How to tune ASP.NET CreateUserWizard?

I have created ASP.NET WebForms site on IIS 7.5. I want to create step by step user registration. I want to store the basic and detailed information about registered users in a specially created database table (not in aspnet_users table). I want to validate email first and then prevent next registration step for the user whose email address already exists in the database. At the last registration step I want to present summary form. All previous input and select fields should be duplicated in this form with "disabled" attribute.
Please tell me how to adjust CreateUserWizard ASP.NET Control and web.config file to these needs?
You can add steps to CUW as shown here:
Customize CUW
Storing Additional Information
Show Summary of user registration
For verification you can set requiresUniqueEmail="true" in your membership element:
Your have several requirements in one question. It would have been better if you had split into different questions.

Resources