0

我正在开发VS2010。这是我的问题:我有一个验证用户的表单,然后将它们重定向到另一个页面。重定向不起作用如果我写用户名和密码系统什么也不说,两个文本框为空:

这是我的登录控件的一部分

<asp:Login ID="LoginUser" runat="server" EnableViewState="false" 
        RenderOuterTable="false" DestinationPageUrl="~/verwaltung.aspx" MembershipProvider="AspNetSqlMembershipProvider">

而且在我的 web.config 我有:

<membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
      </providers>
    </membership>

我怎么解决这个问题?

4

1 回答 1

0

你说你的代码隐藏是空的,实际上当你使用登录控件时,你需要像这样编写登录处理程序。

protected void Login1_Authenticate1(object sender, AuthenticateEventArgs e)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Online"].ConnectionString);
            SqlCommand cmd = new SqlCommand("SELECT FirstName, LastName FROM Account WHERE Username=@Username AND Password=@Password", conn);
            SqlDataReader rdr = null;
            SqlParameter Username = new SqlParameter();
            Username.SqlDbType = SqlDbType.VarChar;
            Username.ParameterName = "Username";
            Username.Value = Login1.UserName.ToString().ToLower().Trim();

            SqlParameter Password = new SqlParameter();
            Password.SqlDbType = SqlDbType.VarChar;
            Password.ParameterName = "Password";
            Password.Value = Login1.Password;

            cmd.Parameters.Add(Username);
            cmd.Parameters.Add(Password);

            try
            {
                conn.Open();
                rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    e.Authenticated = true;//User was found in the database
                    Session["Username"] = Login1.UserName.ToString();
                    Session["Name"] = rdr[0].ToString() + " " + (rdr[1].ToString() == null ? "" : rdr[1]);
                }
            }
            finally
            {
            if (conn != null)
                conn.Close();
            if (rdr != null)
                rdr.Close();
            if (e.Authenticated)
                Response.Redirect("profile.aspx");//Do whatever needs to be done when user gets authenticated
            }
        }
于 2012-06-23T06:01:35.593 回答