Using asp net identity with Web API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is part 22 of asp.net web API tutorial in this video we'll discuss customizing and using asp.net identity server with web API in our previous video we discussed that the users that we have registered using this register. HTML page are stored in a local database that is autogenerated by asp.net identity framework we can find that local database in appor data folder in the solution Explorer if you can't find this database make sure you have clicked on this button which says show all files this database contains several tables as you can see right here now let's understand the purpose of each of these tables so when we doubleclick on this MDF file right here it's going to display us all the tables in server Explorer uncore migration history the presence of this table tells us that it is using Entity framework aspnet roles this Table stores information about roles within our application at the moment we don't have any roles so this table will be empty aspnet user claims this table stores information about claims we don't have any claims either so this table will also be empty aspnet user logins this table is used for thirdparty authentication providers like Facebook Google Twitter Microsoft Etc information about those logins will be stored in this table aspnet user roles this a bridge table which basically tells us which users are in which roles spet users this table stores the new users that we have registered using our register. HTML page so when we right click on this table and when we select show table data we should see all the users that we have registered using our register. HTML page notice in this table we have got you know test 1 2 and 3@gmail.com all the users that we have registered so far using our register. HTML page one obvious question that comes to our mind at this point is can we change the default name of the autogenerated identity database now if you look at the name of the identity database here notice we have this word ASP net followed by that we have a dash and then the name of our project which is employee service and then another Dash and then a timestamp so can we change this default name to for example let's say users DB the answer is yes the thing that controls this name is the connection string that we have in our web.config file so if you look at the web.config file notice we have a connection string with name default connection and here we have that strange name that we see in the app data folder so now if we want the database name to be users DB we have to change it here to users DB and we also need to change it for this initial catalog property so again here we have that strange name so instead of that we are going to use users TB let's save our changes and reload this page now let's register a new user test at test.com let's provide a password and the confirm password let's click register registration successful so we should now have a database with name users DB created so let's go to solution Explorer and click the refresh icon notice within appor data folder we have a database with the name users DB so how to change the default name of the database created by asp.net identity change the name of the database in the default connection string in web.config file another question that we get is can we have the asp.net identity database created in SQL Server rather than an appor data folder the answer is yes we can by changing the default connection string in web.config file to point to your SQL Server let's see how to do that now at the moment we have the identity database created in appor data folder we want this database to be created in SQL Server instead notice within databases folder we don't have users DB to have the identity database created in SQL Server all we have to do is change this default connection string point to your SQL Server so we have to change the data source attribute for that at the moment the value for this attribute is this which is going to create users DB by default in appor data folder instead of that that I'm going to use dot which is basically telling use local SQL Server installation we can also use local instead of dot like that let's see what changes and reload this page now let's register a new user let's provide a password and the confirm password register registration successful now when we refresh this databases for folder notice we see the users DB so this identity database is now created in SQL Server instead of appor data folder and when we look at the tables notice we see all the identity database tables has expected another question that comes to our mind at this point is is it mandatory for the identity tables to be in a separate database can we have them created in an existing database the answer is no it's not mandate for the identity tables to be in a separate database you can have them created by the identity framework in an existing database by just making your connection string point to your existing database let's see how to do that now at the moment our Employee Service web API project is making use of two databases it's making use of this employee DB database which contains our employees table and is also making use of this users DB database which contains the identity tables now what we want to do is have these identity tables also created in employee DB database to achieve that all we have to do is make this default connection string point to our employee DB database and we do that by changing the value for this initial catalog attribute within our default connection string so let's make this point to employee DB database let's save our changes reload our web page and register a new user user let's provide a password and confirm password register registration successful at this point when we refresh the tables folder within our employee DB database notice we see all the identity tables created here as expected in our next video we'll discuss testing asp.net web API token based Authentication using fidler thank you for listening and have a great day
Info
Channel: kudvenkat
Views: 233,111
Rating: undefined out of 5
Keywords: asp net identity change database name in asp.net, asp.net identity sql server database, asp.net identity with existing database, asp.net identity tables, add asp net identity tables to existing database, create asp.net identity database, asp.net web api identity server, asp.net web api identity authentication, asp net identity web api example, identity server web api
Id: Y02ccL4-_K4
Channel Id: undefined
Length: 7min 36sec (456 seconds)
Published: Mon Dec 05 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.