Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have made a login page i want to thing in it 1st i want to define roles nad 2nd make my code authentication soo no one can access from url.
please help me for that


C#
try
            {
                SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Administrator.LENOVO-74FE9906\Desktop\Orignal Project Part 1\Inventory Management System\IMS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
                string query = "SELECT [user].* FROM [user] where u_name='" + txtusername.Text + "' and pwd='" + txtpassword.Text + "'";
                SqlCommand com = new SqlCommand(query, con);
                con.Open();
                if (txtusername.Text == "admin")
                {

                    if (com.ExecuteReader().HasRows)
                    {


                        Response.Redirect("index.html");
                        Label3.Text = "successfully";



                    }
                    else
                    {
                        Label3.Text = "not successfully";
                        txtusername.Text = "";
                        txtpassword.Text = "";
                    }
                }
                else if (txtusername.Text == "user")
                {
                    if (com.ExecuteReader().HasRows)
                    {


                        Response.Redirect("userinventory.aspx");
                        Label3.Text = "successfully";



                    }
                    else
                    {
                        Label3.Text = "not successfully";
                        txtusername.Text = "";
                        txtpassword.Text = "";
                    }
                }

                con.Close();
            }
            catch (Exception ex)
            {
                Console.Write("" + ex.Message);
            }
Posted
Updated 19-May-13 18:50pm
v2

Refer to Below two links

Managing Web Site Users with Roles

How to: Implement Simple Forms Authentication

That will be enough for you to implement the functionality you described.
 
Share this answer
 

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