Search code examples
asp.net-mvcauthenticationvisual-studio-2015localdbnew-project

How to create new project with own database and authentication


I am trying to create a new web MVC project in Visual Studio 2015. I want to use my own database which already exists, and I want to add authentication models and controllers when creating the project.

The issue is:

  1. When I create a new MVC project I can choose the type of authentication but I can't choose what database it uses. So the project is being created with its own local database while I want to use mine so that all necessary tables and DB objects are created in my own database.
  2. I can't even find the LocalDB file created with the project to export the authentication data to my own database.
  3. When I try to connect to the DB it asks me to browse for the mdf file and I have no clue where the file has been created. I did a search in Explorer for the mdf file but found nothing.

Solution

  • I got how to make it working! In case someone has the same problem these are the steps:

    Visual Studio creates the defaultConnection - Yes. But it doesn't create the tables (or probably even the database itself).

    So I did the following:

    1. Installed the project (ASP.NET Core Web Application with Framework template) using Individual User Accounts option as authentication.

    2. Then went to appsettings.json and changed the connection string for my own database. (There is no needs to create asp auth tables, only have your own database ready)

    3. I clicked debug and got the website displayed.

    4. Clicked register and registered new user - I got the screen with button to do the migration.

    5. I clicked the button and refreshed the page.

    6. Went to my database and saw all tables have been created in there and the user inserted in the database.

    I hope this helps anyone.