Visual Studio 2010 and MS SQL 2008- Authentication System using ( JQuery, Json and Web servi

In this article, we will be looking at the login page of the application. An authentication system allows certain online material to be accessible only to a select few. This tutorial illustrates the basic construction of an authentication system using 4.0 in Visual Studio 2010

In this Tutorial, I'll be using JQuery to make AJAX Calls to the server. I'll also explain how to call server side methods or functions directly using JQuery in ASP.Net 4.0 Csharp.


1. Create Project in Visual Studio
2. Solution Explorer
3. Database
1. Create Table
2. Insert statement
3. Create Store Procedure
4. Web.Config
5. Server Side
6. Client Side

First Create a website/Project in Visual Studio 2010.
Next Create a table with Name LoginUser.sql.
User name should be primary key and id should be auto Increment. now question come here why should username be unique because to prevent duplicate user.
now create a store procedure as given in my site.
I have created a method which accepts the user name and password as string and returns the status. If user id exists and if not then 0 returned by the stored procedure based on the availability of user login.

Create a Method as given below

public static string CheckUserName(string userName,string passWord)
string returnValue = string.Empty;
string consString = ConfigurationManager.ConnectionStrings["testingConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(consString);
SqlCommand cmd = new SqlCommand("SPX_CHECKUSERLOGIN", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", userName.Trim());
cmd.Parameters.AddWithValue("@password", passWord.Trim());
returnValue = cmd.ExecuteScalar().ToString();
catch(Exception ee)
returnValue = "error"+ee.Message;
return returnValue;

Client Side:
In head tag write Jquery function to call method from server side as given below

function CheckUserLogin() {
type: "POST",
url: "default.aspx/CheckLogin",
data: '{userName: "' + $("#<%=txtUserName.ClientID%>")[0].value + '",passWord: "' + $("#<%=txtPassWord.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {

have you seen in this function data is send user name and password to server side method. I am simply calling the CheckLogin Server side function in Default.aspx page and passing the TextBox values as parameter. Secondly I have defined the success method OnSuccess that will be called handle the response returned by the Server.

Note:Method should be static.


Related Articles

ASP.NET 4 Brings Clean Web.config Files

Major configuration elements have been moved to the machine.config file in .NET 4 With the advent of the latest iteration of Microsoft's development platform and tools, the company took a number of steps designed to result in optimized desktop and Cloud applications for devs, simply by leveraging Visual Studio 2010 and .NET Framework 4. An illustrative example in this regard is the new Web.config file that can accompany ASP.NET 4.

More articles: JQuery Json and Web services. SQL 2008 Authentication 4.0 Visual Studio 2010


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: