I want to create an application that uses individual user accounts identity functionality of MVC. I also want to harness this functionality in order to extend the application so I can add new fields to the register page so that it populates not only the AspNetUsers Table, but also to a custom table that I had made locally within Visual Studio called Customers. I've set up the table so that the customer table has a foreign key field for the GUID that is produced when a ASPNetUser is created. So far, ive found it challenging as I dont really know where to start and find other tutorials I found not really answering my question.
Does anyone have any tips? is this going to be harder than starting an MVC application and then adding in identity functionality afterwards in order to achieve this goal?
Thanks
Related
I am developing an mvc app in .net core 5 (it is an online click-based rpg). I have decided to choose individual accounts athutentication at the start.
I have alter-tabled the initial AspNetUser table to have a foreign key of another table (I want a user to have a character linked to it).
Now I have a view which needs altering based upon logged in user having or not having a character. I know I have to go with seme kind of viewmodel. But the problem is that I have no access to the original class which the AspNetUser table was maped from. It is just not be found in the code. I assume the class does not exist and Visual Studio just gave a cue to my database to create those tables. But I need such class to exist in order to carry on with my coding.
What would you suggest I do now please?
Is there a way to make Visual Studio create necessary classes from the tables?
Thank you and have a grand day.
I am trying to update an older website. It already has an existing database with a user and a role table, with existing data in it.
I need to create a new web-api and a new web project and integrate ASP.NET Identity into the already existing database.
I have currently setup my solution to breakup the projects as follows:
Domain
Services
WEB_API
WEB_UI
My aim is to implement the Identity in the services layer so that both my WebAPI and MVC site can utilize the same identity mechanism.
I am fairly overwhelmed at the moment, I have read many tutorials and articles over the last day or two and have ended up with the options of either re-implementing the IUserStore and IRoleStore. And also with mapping the different entities in the OnModelCreatingMethod.
I cant seem to find a tutorial which is aimed at what I want to do. My database is to different to simply remap the names of columns, And I dont want to re-implement the entire Identity Stores as there are only a few conflicting fields. Most tuts I have found are related to using mysql instead of EF. I still want to make use Entity Framework.
Issues I have:
The current Users Table in the database used Int pk , not GUID
The Password Field uses a different Hashing algorithm. So i would need to override how Identity checks and store the password.
I do not have all the required Identity User fields in my database, however I am able to add new fields, I just cant change already existing fields.
I am making use of Database First as the DB already exists.
So basically my question is, In what direction do I need to go in order to overcome the above mentioned issues. Can I get away with changing the Database mapping? Or do I need to go as far as re implementing the User and Role Stores?
What I had initially planned was to re-implement the User and Role Stores using entity framework, And i could then make use if the DB first model classes and map the actual DB structure and fields to my ApplicationUser Fields. But this is where I thought I might be diving into cold waters, and i'm generally not a fan of reinventing the wheel if not necessary.
-The first thing you should do if you haven't already is to BACK-UP your current database!
You could use code first to update an existing database.
I found this walkthrough and it seemed close to the route you're on, and I'm hoping it will help solve your problem, begin at "Migrating to Visual Studio 2013".
http://www.asp.net/identity/overview/migrations/migrating-an-existing-website-from-sql-membership-to-aspnet-identity
This would create a few new tables, but not necessarily a new database.
Download Nuget packages:
Microsoft.AspNet.Identity.EntityFramework,
Microsoft.AspNet.Identity.Owin,
Microsoft.Owin.Host.SystemWeb
Enable-migrations and run a script such as this: https://aspnet.codeplex.com/SourceControl/latest#Samples/Identity/SQLMembership-Identity-OWIN/Migrations.sql
Or you could try using a reverse POCO generator found in visual studio extensions.
(My 1st attempt at writing an answer here. Tried to clarify.)
I am currently new to ASP .Net MVC and I'm working on a project. I already created my database which has a Employees table (which will consist of the users of the system) where I would want to manage all employees. I know mvc comes with a built in functionality that creates the roles and users table for you from code migration. How would I be able to implement that with my own database? Another problem, I tried creating a default and script the tables, added them to my database but the primary keys which is of type int doesn't match that of the id in the dbo.aspnetusers table that was created.
Can anyone assist me?
Regards
Your problem is bit unclear. but from what i have understood so far i can say that if your application is to be used internally, then you should consider using windows authentication and implement your own role provider.
Additionally you will need to provide more detail on what your are trying to achieve. this sounds to me like more of a design question rather than implementation question.
I created a login system for one MVC App based on the new Identity framework, and since I already went through all the hard work of modifying my database to match the Identity 2.0 requirements, I was wondering if it would be possible to use it outside of MVC, so I could reuse what I already created, like a login system for a desktop project that I'm working on for example. If so, can I implement the login system on a .dll that can be reused on other projects?
Yes, you could use your existing database for another application. Add the ADO.NET Entity Data Model, and point it to your database. Then, if you need to, select "Update Model from Database" and you should be all set.
Although, it may be just as easy to create your own user/roles tables. It's frustrating (to me) that Identity creates the Primary keys as strings, even though they are essentially Guids.
I am a bit newbie in ASP.NET and i don't really understand where should save some of the data that is related to my users.
Ill explain myself:
I use ASP 2.0 and i created a simple app that has registration and login mechanism. That data is stored in a DataBase that ASP automatically prepared for me (ASPNETDB.MDF)
I see the following user related data in that database:
These are my doubts:
Can i add there another 3 columns for other data related to the user?
Should i create a new table within this database and link it to aspnet_Users with a FK?
Should i create a new database different than this one(This is just for security and similar stuff)?
If 3 is yes, how will i know witch row of data is related to witch user in the ASPNET.DB?
I am very confused, could someone tell me where should i store my other data related to user(age, city,bloodtype...)
You will have to create a seperate table if you want it to be easy. A lot of the user loading and saving is done through provider classes and you will probably tie yourself in knotts trying to customise all that.
If you are starting out, it's going to be better to create a seperate user table for extended detail on the user that you can access and edit at will.