Click here to Skip to main content
16,021,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please anyone can tell me how to build login page?
i mean how could someone prevent the user from surfing the website without logging in ??? please help me with the code.
Posted

Please use form based authentication(for internet users) and SQLMembership provider.

Step 1: Create SQL database using aspnet_regsql tool.
Step 2: Configure the application with the newly created SQL database using Website Administration tool.
Step 3: Create users using Website Administration tool.
Step 4: Put Web.config details
Step 5: Create login page using ASP.NET login controls.

There are several helpful articles available in internet to do this.
 
Share this answer
 
Comments
Orcun Iyigun 28-Dec-10 11:57am    
Yes.Membership is the best and easiest way for that.
Well here is the link for the membership. Almost no code necessary.
http://msdn.microsoft.com/en-us/beginner/bb308874.aspx[^]
 
Share this answer
 
public partial class _Default : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(@"Data Source = A\SQLEXPRESS;Initial Catalog=bank;Integrated Security = True");
        SqlDataAdapter ada;
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnlogin_Click(object sender, EventArgs e)
        {
            try
                {

                string struname = txtusername.Text;
                string strpwd = txtpwd.Text;
                ds = new DataSet();
                ada = new SqlDataAdapter("SELECT * FROM users WHERE Username = '" + struname + "' and Password = '" + strpwd + "'", con);
                ada.Fill(ds, "users");
                if (Convert.ToBoolean(ds.Tables["users"].Rows[0]["IsAdmin"].ToString() == "True"))
                {
//This page redirects to Admin Page//
                    Response.Redirect("AdminScreen.aspx");
                }
                else if (ds.Tables[0].Rows.Count == 0)
                {
                    Response.Write("<script>alert('Please check the Username and Password')</script>");
                    clearcontrols();
                    txtusername.Focus();
                }
                else
                {
// This webpage redirects to the User Page//
                    Session["Id"] = ds.Tables[0].Rows[0][0].ToString();
                    Session["username"] = ds.Tables[0].Rows[0][1].ToString();
                    
                }
            }
            catch
            {
                Response.Write("<script>alert('Please check the Username and Password')</script>");
            }
            

        }
        public void clearcontrols()
        {
            txtusername.Text = "";
            txtpwd.Text = "";
        }
    }
}
 
Share this answer
 
v2
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900