WebService to Create Users using ASP.Net

Here i will show you how to create a webservice to creating users using aspnetdb(database)  using asp.net membership provider

First let me startup with the configuration. For this you gotta navigate to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 and execute aspnet_regsql.exe  which in turn will open up with a window which is nothing but application service configuration for sql server.

You can run Aspnet_regsql.exe without any command-line arguments to run a wizard that will walk you through specifying connection information for your SQL Server installation, and installing or removing the database elements for the membership, role management, profile, Web Parts personalization, and health monitoring features. You can also run Aspnet_regsql.exe as a command-line tool to specify database elements for individual features to add or remove, using the options listed in the table below.

If you want to give out the aspnet to configure with custom database then configure with the custom database name else just move on with next– next–next and finish which will get configured with aspnetdb which is the default database.

Then Create a new web service project in visual studio. Navigate to web.config file and enter this connection string under </appsettings>



<add name=”LocalSqlServer”

    connectionString=”Data Source=(your server name);Initial Catalog=aspnetdb;User ID=(username);Password=( password);Integrated Security=SSPI”

    providerName=”System.Data.SqlClient” />


which ll be configured with the default database aspnetdb.

Let’s next move on to the service. Let me call this service as CreateUser so the file name will be generated as CreateUser.asmx and CreteUser.asmx.cs

Enter the following line of codes :


using System;

using System.Data;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.ComponentModel;

using System.Web.UI.WebControls;

using System.Web.Security;


namespace WP_CreateUser_SAP


    /// <summary>

    /// Summary description for CreateUser

    /// </summary>

    [WebService(Namespace = “http://dev.techmachi.com/”)]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]


    public class CreateUser : System.Web.Services.WebService


        MembershipCreateStatus status;

        MembershipUser user;

        string Message;


        string Success = “The user account was successfully created!”;

        string DuplicateUserName = “There already exists a user with this username”;

        string DuplicateEmail = “There already exists a user with this email address”;

        string InvalidEmail = “There email address you provided in invalid”;

        string InvalidAnswer = “There security answer was invalid”;

        string InvalidPassword = “The password you provided is invalid. It must be & Membership.MinRequiredPasswordLength.ToString &  characters long and have at least one non-alphanumeric character.”;

        string Other = “There was an unknown error; the user account was NOT created”;


        public string CreateUsers(string username,string password,string email,string passwordquestion,string passwordanswer)




                user = Membership.CreateUser(username, password, email, passwordquestion, passwordanswer, true, out status);

                switch (status)


                    case MembershipCreateStatus.Success:

                       Message = Success;


                    case MembershipCreateStatus.DuplicateUserName:

                        Message = DuplicateUserName;


                    case MembershipCreateStatus.DuplicateEmail:

                        Message = DuplicateEmail;


                    case MembershipCreateStatus.InvalidEmail:

                        Message = InvalidEmail;


                    case MembershipCreateStatus.InvalidAnswer:

                        Message = InvalidAnswer;


                    case MembershipCreateStatus.InvalidPassword:

                        Message = InvalidPassword;



                        Message = Other;



                return Message;


            catch (Exception ex)


                return ex.ToString();







Thats it .. when you run the service it ll promt for 5 Credentials which will be the input . Execute and Enjoy.
Tagged on:

One thought on “WebService to Create Users using ASP.Net

  1. Pingback: WebService to Create Users using ASP.Net | Dev Techie

Leave a Reply

Your email address will not be published. Required fields are marked *