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

标签 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

最佳答案

对于标志,你应该使用一点,但这应该可以工作

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

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

关于c# - 从数据库获取标志并在身份验证中设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5571350/

相关文章:

mysql - 如何在MySQL中获取多个字段的不同?

c# - 如何使用mysql命令条件语句在 Crystal 报表中显示数据?

c# - COSMOS - 操作系统开发 - 错误设置未启动?

c# - 组合框数据库值

c# - 找不到类型或命名空间名称 'type/namespace'.. - Asp.Net - C#

c# - asp.net 回发超时

asp.net - UserControl 没有名为 ContentTemplate 的公共(public)属性

mysql - SQL 显示从不更改但根据需要更新其他列的列的静态值

c# - 在使用 asp.net 尝试登录 5 次失败后,如何将用户帐户锁定 30 分钟?

c# - 在用户控件 asp.net 中声明事件?