从数据库获取标志并在身份验证中设置

时间:2011-04-06 18:40:40

标签: c# asp.net mysql sql html

不知道是否有人可以帮我这个我在我的用户表中设置了一个标志选项,想知道如何在重定向之前将其绑定在if语句中?

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        //database connection string
        OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando; OPTION=3;");
        cn.Open();
        OdbcCommand cmd = new OdbcCommand("Select * from User where username=? and password=?", cn);
        //Select the username and password from mysql database in login table
        cmd.Parameters.Add("@username", OdbcType.VarChar);
        cmd.Parameters["@username"].Value = this.Login1.UserName;
        cmd.Parameters.Add("@password", OdbcType.VarChar);
        cmd.Parameters["@password"].Value = this.Login1.Password;
        //use asp login control to check username and password
        OdbcDataReader dr = default(OdbcDataReader);
        dr = cmd.ExecuteReader();
        if (dr.Read())
        {

            string theUserId = Convert.ToString(dr["UserID"]);
            Session.Add("UserID", theUserId);
            e.Authenticated = true;
            string flagoption = Convert.ToString(dr["flag"]);
            if (flagoption = 0) //error
            }
            //add some kind of if statement
            Response.Redirect("Uploadpicture.aspx");
            {
            else
            {

            //if flag is set to 0 redirect to upload picture page:
            Response.Redirect("UserProfileWall.aspx");
            // if flag is set to 1 redirect to to users profilewall:
            // Event Authenticate is true forward to user profile
            }
        }
      }
    }
  }

enter image description here

1 个答案:

答案 0 :(得分:1)

对于标志你应该使用一点但是这应该工作

int flag =Int32.Parse(dr["flag"]);

if(flag != 1)
Response.Redirect("Uploadpicture.aspx");
else
Response.Redirect("UserProfileWall.aspx");