was successfully added to your cart.

What If I Want to Create the Tables Myself for ASP.NET Authentication?

What If I Want to Create the Tables Myself for ASP.NET Authentication?

By March 6, 2018 Ask Tim No Comments

Alternatives to Code First Database Scripting

I totally get this. So the way ASP.NET authentication is set up (which you can see in this video: https://youtu.be/kpSwmLlMu9E), when you run the application for the first time and you actually access the database, it checks to be sure the database and tables are all there. If not, it builds the tables just in time and then runs the code. That is convenient for development but absolutely scary for production. Fortunately, you have options. First, you can take a copy of the database created in development and use it in production. When your production application runs, as long as it is pointing at that database copy, it will run without issue. However, that seems cludgy.

The other way to do this is to create the database in development and then convert the tables into scripts (there are only six of them). Run those scripts in whatever database you want for production and you will be good to go. Just make sure you execute them in the correct order (some tables rely on other tables). To make things even easier, if you use the default security setup (meaning you don’t add extra fields to the tables), I have created a single script (download it here: OAuthSQLScript.zip) that you can download and run that should solve this issue.

One quick note – I would recommend keeping your authentication database separate from your database that holds your data (if that makes any sense). Having it in a separate database allows you to improve the security around something that should be as secure as possible.

Leave a Reply