Register new user using asp net core identity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is part 66 of asp.net core tutorial in this video we'll discuss how to register a new user using asp.net core identity we won't have a user registration form to look like this we want to capture user email which will be used as the username to log in and then his password and then finally another field to confirm the password they have provided the first thing that we want to do is create a view model class that's gonna carry the data from this use a registration view to the controller so let's have that class to the view models folder in our project right-click on the folder add new item we want to add a class let's name this class register view model in this register view model class I'm going to include three properties to capture user email password and confirm password in the interest of time I'm going to paste the required code and then walk you through it there's nothing new that's going on here but it's just all these concepts in our previous videos in this series so the code here should be pretty straightforward to understand we have a register view model class we discussed view models in detail in part 26 of this SP dotnet core tutorial in this view model class we've got three properties email password and confirm password on these properties were using built in asp.net Co validation attributes for model validation we see red squiggly lines to fix that let's bring in the required namespace by pressing control period we know this validation attributes are present in system dot component model dot data annotations namespace let's bring the ten email is a required field so we using the required validation attribute we also want to ensure a valid email address format is provided to validate against that they using the email address validation attribute password is also a required field as we type the password in the password text box on the UI we do not want to display the typed characters instead we want to mask those characters for that using the password validation attribute so the same is true even for confirm password notice in the property name confirm password we do not have a space between the words confirm and password but when we display a label for this field on the UI we want to include a single space between the words confirm and password for that using the display attribute we are also using the compare attribute because we want to compare the password that we type in the confirm password field where the value that is typed in the password field the name of this property is specified right here and if they do not match this is the error message that we want to display password and confirm ation password do not match we discussed these validation attributes and model validation in detail in parts 42 and 43 of our asp.net core tutorial so if you're new to these concepts please check out these videos this register view model class carries the data from this register view to the controller and the controller will do the rest I'm going to name the controller account controller because we are dealing with user accounts here creating reading updating and deleting user accounts so back in our project let's right click on the controllers folder add new item we want to add a controller let's name our controller account controller the name of the action method is register so when a get request is issued to slash account slash register this is the X method that responds and it's going to return our register view at the moment we do not have the register view the name of the controller here is account controller so the first thing that we want to do is in the views folder let's add a new folder with named account and this folder is going to contain all the views of this account controller right click on the account folder add new item we want to add a razor view and let's name our view register dot C sh t ml as you might have guessed already the model for this view is this register view model class so let's copy the name of the class and specify that as the model in the interest of time I'm going to paste the required code again there should be nothing new to you in this code because we discussed all these concepts in detail in our previous videos in the series so let me quickly walk you through what this code is doing first we're using the view bag object title property to set a page title to use a registration and then here we're using bootstrap for two style of a registration view and when this form is submitted we want to issue a post request so on the form tag we are setting the method attribute to post and then we are using the validation summary tag helper to display any validation errors we might have and then we have a div element here which contains a label an input element and a span validation element for email field the same is true even for password we have a label input element and a span validation element and then finally the same for confirm password and then we have the submit button here the text on the button is register when this button is clicked we will issue a post request and this form data is submitted to the server but it's just all these form tag helpers and issue in post requests to the server in detail in this asp.net core tutorial playlist in the layout view let's include a navigation menu item to get to the register view here we have the list and create navigation menu items let's make a copy of this menu item and then change the bets that are required the text on the navigation menu item is register and when this navigation menu item is clicked we want to get to the account controller and register action within that account controller let's save all these changes and run our project notice we have a register navigation menu but we actually want it on the right-hand side right here so all our registration and login related navigation menu items should be on the right-hand side here and all our application navigation menu items like list and create on the left-hand side here so to move this register link to the right-hand side what I'm going to do is create another are not add list here and then use the same bootstrap now bar - nav class and then move this Ally element inside this unordered list and then to push this register navigation menu item to the right hand side I'm going to use another bootstrap styling class ml - order notice now we have the register navigation menu item on the right and when we click that the URL changes to slash account slash register and we see our user registration view at the moment when we submit this form by clicking this register button notice the same user registration view is re-rendered this is because the register action that we have within our account controller it is responding to both HTTP GET and HTTP POST when a post request is issued it is the same action method that is executed and all this method is doing is returning us that same register view so we see the register view re-rendered we want this register action to respond only to HTTP GET and not HTTP POST so let's decorate it explicitly with HTTP GET and save our changes notice now when we issue a post request by clicking the register button we see not found error that's because at the moment within our account controller we do not have an action method that can handle the post issued by our register view well this is how to do that in our next video we'll handle the post request when this register button is clicked create a user account with the provided data on this form that's said in this video thank you for you [Music]
Info
Channel: kudvenkat
Views: 156,439
Rating: undefined out of 5
Keywords: asp.net core user registration, asp.net core 2.0 user registration, asp.net core identity register user, asp.net core identity usermanager, asp.net core identity signinmanager, asp.net core mvc user registration, asp.net core mvc create user view, asp.net core mvc register user
Id: sPbDrqpme_w
Channel Id: undefined
Length: 9min 6sec (546 seconds)
Published: Tue Jun 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.