0

Hi i have a simple custom member ship provider:

Can anyone help me with a simple if statement or switch case where i can route administrators to one page and users to another?

I am currently using the asp.net login controls and dont see how i can specify two different locations depending on the user.

Many Thanks

Grant

my login code:

public override bool ValidateUser(string username, string password)
    {

        SqlConnection conn = new SqlConnection(_connectionString);

        try
        {
            conn.Open();
            string sSQL = "select * from users where U_Name = @username and U_password = @password";
            
            SqlCommand comm = new SqlCommand(sSQL, conn);
            comm.Parameters.AddWithValue("@username", username);
            comm.Parameters.AddWithValue("@password", password);

            SqlDataReader dr = comm.ExecuteReader();

            if (dr.HasRows)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

        finally
        
        {
            conn.Close();
        }
    }
2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by gdp_87
0
// i hope you might have roles while doing this..
//which would be Admin, NormalUser
// if user in Admin Role then
FormsAuthentication.SetAuthCookie(UserName.Text,RememberMe.Checked)
Response.Redirect("AdminPage.aspx");

// if user in Normal Role then
FormsAuthentication.SetAuthCookie(UserName.Text,RememberMe.Checked)
Response.Redirect("NormalPage.aspx");

that's the best way to resolve this problem.
if you wanna learn more then
http://asp.net/learn/security/

0

Hi Thanks for the reply,

I was hoping to just modify the validate user event in the membership provider as i havent implemented roles as that would be too overkill for what i need.

Any ideas?

thanks.
grant

0

Sorry,

I mean is there a way i can add in my code above some like

if role = admin {go here} else {go here}

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.