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>
connectionString=”Data Source=(your server name);Initial Catalog=aspnetdb;User ID=(username);Password=( password);Integrated Security=SSPI”
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 :
/// Summary description for CreateUser
[WebService(Namespace = “http://dev.techmachi.com/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CreateUser : System.Web.Services.WebService
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);
Message = Success;
Message = DuplicateUserName;
Message = DuplicateEmail;
Message = InvalidEmail;
Message = InvalidAnswer;
Message = InvalidPassword;
Message = Other;
catch (Exception ex)