Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

ASP.NET Web API user registration

Suggested Videos
Part 18 - Implementing basic authentication in ASP.NET Web API
Part 19 - Call web api service with basic authentication using jquery ajax
Part 20 - ASP.NET Web API token authentication

In this video we will discuss implementing new user registration page. This is continuation to Part 20. Please watch Part 20 from ASP.NET Web API tutorial before proceeding.

The registration page should be as shown below.
ASP.NET Web API user registration

For a new user to register they have to provide
1. Email address
2. Password 
3. Confirm password 

When all the fields are provided and when the Register button is clicked, the new user details should be saved and a modal dialog should be displayed as shown below. web api register user

To achieve this, add an HTML page to EmployeeService project. Name it Register.html. Copy and paste the following HTML and jQuery code.

<!DOCTYPE html>
    <meta charset="utf-8" />
    <link href="Content/bootstrap.min.css" rel="stylesheet" />
<body style="padding-top:20px">
    <div class="col-md-10 col-md-offset-1">
        <div class="well">
            <!--This table contains the fields that we want to capture to register a new user-->
            <table class="table table-bordered">
                    <tr class="success">
                        <th colspan="2">
                            New User Registration
                        <td><input type="text" id="txtEmail" placeholder="Email" /> </td>
                        <td><input type="password" id="txtPassword"
                                   placeholder="Password" /></td>
                        <td>Confirm Password</td>
                        <td><input type="password" id="txtConfirmPassword"
                                   placeholder="Confirm Password" /></td>
                    <tr class="success">
                        <td colspan="2">
                            <input id="btnRegister" class="btn btn-success"
                                   type="button" value="Register" />
            <!--Bootstrap modal dialog that shows up when regsitration is successful-->
            <div class="modal fade" tabindex="-1" id="successModal"
                 data-keyboard="false" data-backdrop="static">
                <div class="modal-dialog modal-sm">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">
                            <h4 class="modal-title">Success</h4>
                        <div class="modal-body">
                                <h2 class="modal-title">Registration Successful!</h2>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-success"
            <!--Bootstrap alert to display any validation errors-->
            <div id="divError" class="alert alert-danger collapse">
                <a id="linkClose" href="#" class="close">&times;</a>
                <div id="divErrorText"></div>

    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {

            //Close the bootstrap alert
            $('#linkClose').click(function () {

            // Save the new user details
            $('#btnRegister').click(function () {
                    url: '/api/account/register',
                    method: 'POST',
                    data: {
                        email: $('#txtEmail').val(),
                        password: $('#txtPassword').val(),
                        confirmPassword: $('#txtConfirmPassword').val()
                    success: function () {
                    error: function (jqXHR) {

Please note : 
1. The ajax() method posts the data to '/api/account/register'
2. You will find the Register() method in AccountController in Controllers folder
3. AccountController is provided by ASP.NET Web API, which saves data to a local membership database

In our next video we will discuss where the users registration data is stored and all the customizations that can be made.

ASP.NET Web API tutorial for beginners


  1. Hello everyone i am showing a webpage using Iframe i am also passing ID and Article from my gridview but now i want to show this webpage using POPUP window.How to do that. Please Help. Here is my code

    Iframe1.Attributes.Add("src", "Drawing2.aspx?ID=" + grdrow.Cells[1].Text + "&Article=" + grdrow.Cells[2].Text + "&testdrawing= kkk");

  2. i am getting 400 error like this
    Failed to load resource: the server responded with a status of 400 (Bad Request)

    1. When u r doing a ajax request make sure your URL has a absolute address

    2. if you using MVC then your url should be like this @url.action(action,controller)..or
      make a hidden file in view and specify url.
      and get that filed val in jquery...

      if you using webforms then your url should be like this.
      thank you

  3. while running same code in my pc this error is coming.please sir help in this
    {"Message":"The request is invalid.","ModelState":{"model.UserName":["The UserName field is required."]}}

  4. in ajax call change property email to UserName

  5. can you please add the code of accountcontroller

  6. Hi I hope you can still see this, but i am still trying to learn how to do all this.
    Because I created a Web API project that will be the "Web Service" for my project. My Web API contains the Identity Framework, now I need to create a MVC client project that will connect ( Register/Login/Interact ) to my Web API Project.

    I am aware that i need to have the same model structure as my web api project to be able to access the things i need on my Web API.
    My question is, do i need to create my MVC client project with Indvidual User Accounts? or Should I just create a plain MVC project?


    ~ Pat

  7. i am getting a following error can anyone please help me {"Message":"The request is invalid.","ModelState":{"":["Passwords must have at least one non letter or digit character."]}}

  8. Hi there, try as password: Welcome$01
    It should work. There are some rules for the password!
    That's why you got the error.

  9. Could you also make a tutorial on how to change it from uning a LocalDB in the project folder to use a ()external MS SQL Server, i cant get to to work. and since you in the previous episode uses a MS SQL Server for the Employee Data why not continue to use that databse.

  10. Hey, did everything just as the video, even copied the code to my Register.html source but once the Register button is clicked nothing happens, not even the errors show. Any idea of why is this happening?


If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.