How to create a login page in Aspnet with sqlserver

First we have to create a database for storing the login information

Open the Sqlserver Management studio

Create a new database and change the database name as db_Logininformation

Create a New table in that database(db_Logininformation) and change the table name as tab_userinformation
Now, create the following fields

  1. UserID   int         PrimaryKey  
  2. username varchar(50)  
  3. Password varchar(50)  
Next, Enter the some usernames and paasword directlu in the database for checking purpose

and save the table

Next ,open the Microsoft visual studio 2008

Next,select the Aspnet web application and change the name as LoginPage

Next,come to the design page of LoginPage and drag and drop two labels,two textboxes and button

next,come to the code page of the Login.aspx.cs

Write the following codein the page event
 
  1. protected void Button1_Click(object sender, EventArgs e)  
  2.     {        
  3.         con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ToString());  
  4.         con.Open();  
  5.         com = new SqlCommand("select Password from userinformation where Username='" + txt_uname.Text + "'", con);  
  6.         dr = com.ExecuteReader();  
  7.         if (!dr.Read())  
  8.         {  
  9.             Response.write("Invalid User");  
  10.         }  
  11.         else  
  12.         {  
  13.             if (dr[0].ToString() == txt_pwd.Text)  
  14.             {  
  15.                 Response.Redirect("~/mainPage.aspx");  
  16.             }  
  17.             else  
  18.             {  
  19.                Response.write("Wrong Password");  
  20.                txt_pwd.Focus();  
  21.             }  
  22.         }  
  23.   
  24.     } 

How to Create ASP.NET Session Login Without Cookies

The following describes the easiest way I have found to force users to log into an ASP.NET website for each session but not require them to accept cookies. You must do the following things.
  1. Create a Web.config file with the appropriate entries to allow session state management.
  2. Create a well formed Global.asax file with the code below included in it.
  3. Create a login page to authenticate users against a database or whatever method you desire.
' Fires when the session is started and sets the default loggedin state to ""

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("Loggedin") = ""
CheckLoggedIn()
End Sub
Collapse
' Called when the request has been process by the Request Handler and 

' HttpSessionState is available [This is the key piece of code that forces 

' the user is login check with each page request]

Sub Application_OnPostRequestHandlerExecute()
CheckLoggedIn()
End Sub
Collapse
'Check that the user is logged in.

Sub CheckLoggedIn()
'If the user is not logged in and you are not currently on the Login Page.

If Session("LoggedIn") = "" And InStr(Request.RawUrl, "Login.aspx") = 0 Then
Response.Redirect("~/Login/Login.aspx")
End If
End Sub
Finally create a Login.aspx file that authenticates the user. If the user is allowed in, set: Session("Loggedin") = "Yes"
That's all there is to it. Hope this helps! Enjoy!