0

私は ASP.Net アプリケーションを使用しており、このチュートリアルHEREに従ってログインページを作成しましたが、ログインしようとすると、Seller_login.aspxページに戻りませんHome.aspx page! ブラウザーにログインした後、ユーザー名とパスワードを覚えておきたいかどうか尋ねられたので、ログイン プロセスは正常に機能していると思います。しかし、ホームページの唯一の問題!助けてください。

web.configコード:

<authentication mode="Forms">
  <forms defaultUrl="~/Home.aspx" loginUrl="~/Seller_Login.aspx" slidingExpiration="true" timeout="2880"></forms>
</authentication>

Seller_login.aspx.csコード:

protected void ValidateUser(object sender, AuthenticateEventArgs e)
{
    int userId = 0;
    string constr = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("Seller_Validate_User"))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Username", Login1.UserName);
            cmd.Parameters.AddWithValue("@Password", Login1.Password);
            cmd.Connection = con;
            con.Open();
            userId = Convert.ToInt32(cmd.ExecuteScalar());
            con.Close();
        }
        switch (userId)
        {
            case -1:
                Login1.FailureText = "Username and/or password is incorrect.";
                break;
            case -2:
                Login1.FailureText = "Account has not been activated.";
                break;
            default:
                FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMeSet);
                break;
          }
     }
}

Home.aspx.csコード:

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.Page.User.Identity.IsAuthenticated)
    {
         FormsAuthentication.RedirectToLoginPage();
    }
}
4

0 に答える 0