Best Cloud ASP.NET Hosting :: Login Form Using Session in ASP.NET C#

BestCloudHostingASP.NET | Hello guys today I will share tutorial about how to make login form using session in ASP.NET. Let me to show you. t has the two inputs username and password and a login button. When the user clicks the login button the user is redirected to a new page (his account page). In this account page we have a logout button. When he clicks he goes out from his account page and returns to his login page with the saved username and password, the user doesn’t need to fill it in again, it is saved in the session using a browser cookie.

INITIAL CHAMBER

Step 1

Open your Visual Studio 2010 and create an Empty Website, provide a suitable name (LoginForm_demo).

Step 2

In Solution Explorer you get your empty website, then add two web forms and a SQL Server Database as in the following.

For Web Form:

LoginForm_demo (your empty website) then right-click then select Add New Item -> Web Form. Name it Login_demo.aspx. Again get to the same process and add another web form and name it  Redirectpage.aspx.

For SQL Server Database

LoginForm_demo (your empty website) then right-click then select Add New Item -> SQL Server Database. (Add a database inside the App_Data_folder).

DATABASE CHAMBER

Step 3

In Server Explorer, click on your database (Database.mdf) then select Tables -> Add New Table. Make the table like this.

Table  tbl_data (Don’t Forget to make ID as IS Identity — True)

Data Table1

Figure 1: Data Table

Now enter some data in your database by going to Tables then right-click then select Show Table Data and enter whatever you want to add in the username and password. I had entered this data.

Enter the Data2

Figure 2: Enter the Data

We will match this username and password so if the data is correct, the user is redirected to his account page or otherwise the user gets an error message.

DESIGN CODE

Step 4

Now make some design for your application by going to Login_demo.aspx and try the code as in the following.

Login_demo.aspx

 You will get something like this:

Output1

Figure 3: Output1

CODE CHAMBER

Step 5 We will make some code in the Login_demo.aspx.cs page so that our login form works.

Login_demo.aspx.cs

Login Demo

Figure 4: Login Demo

 Design your Redirect Form Page so that user is redirected to his account page.

RedirectForm.aspx

 Redirectform.aspx.cs

 I hope this article helpful for you 🙂 Happy coding

Rate this post