Umbraco 用户控制用户日志记录的数据库连接问题



我为Umbraco开发了一个用户登录用户控件。我正在使用 SQL Server 2008 数据库。在用户控件中,我放了一个尝试捕获块。因此,一旦我单击登录按钮,它就会给出 Null 值异常。这是我的代码。

        protected void Button_Click(object sender, EventArgs e)
    {
        string username = TextBox1.Text;
        string password = TextBox2.Text;
        try
        {
            String connstring = ConfigurationManager.AppSettings["umbracoDbDSN"].ToString();
            SqlConnection sc = new SqlConnection(connstring);
            sc.Open();
            SqlCommand scmd = new SqlCommand("SELECT email,passwd FROM umbUser");
            SqlDataReader sdr;
            sdr = scmd.ExecuteReader();
            while (sdr.Read())
            {
                String uname = sdr.GetString(1);
                String pwd = sdr.GetString(2);
                if ((username.Equals(uname)) && (password.Equals(pwd)))
                {
                    TextBox1.Text = "Correct";
                }
                else
                {
                    TextBox1.Text = "Wrong";
                }
            }
            sc.Close();
        }
        catch (Exception e5)
        {
            TextBox1.Text = "" + e5;
        }
    }

想要重写现有的 .net 成员资格提供程序和功能以从头开始编写自己的提供程序和功能似乎不寻常。为什么不使用现有的成员资格功能,而只使用标准 .net 控件。代码将比您尝试使用代码示例执行的解决方案更具弹性,我很抱歉地说这将非常低效。

看看这个 - http://our.umbraco.org/wiki/how-tos/membership-providers

最新更新