Click here to Skip to main content
15,914,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello experts,

I am writing a web application where i want to implement role based security with form authentication. But I do not want to use the ASPNETDB.MDF database so i created my user table which has these colomns: UserName, Password, Role.

I wrote a class below:

public bool Login()
{
    SqlConnection con = new SqlConnection(this.ConnectDB());
    SqlCommand cmd = new SqlCommand();
    SqlDataReader rdr = default(SqlDataReader);
    {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "sp_Login";
        cmd.Parameters.AddWithValue("@Password", Password);
        cmd.Parameters.AddWithValue("@Username", Username);
        cmd.Connection = con;
    }
    bool userfound = false;
    try 
    {
        con.Open();
        rdr = cmd.ExecuteReader();
        if (rdr.Read()) 
        {
            userfound = true;
            this.Role = rdr("Role");
        }
    }
    catch (Exception ex) 
    {
        msg = "Invalid Username or Password" + ex.Message.ToString();
    }
    finally 
    {
        con.Close();
    }
    return userfound;
}


In my LoginButon_Click event i used

Session("Role") = objlogin.Role;


but the role is save in the session, hence i cant restrict people who are not in particular role not to access some pages.

Please is there any better way i can do this without ASPNETDB.MDF database.
Posted
Updated 16-Mar-10 7:07am
v3

1 solution

You can use a SQL Server database, run aspnetregsql[^] to create and configure the database tables. Otherwise you'll need to create an implementation of MembershipProvider[^] and RoleProvider[^]
 
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