我正在使用ASP.Net应用程序,我已按照本教程HERE创建了一个登录页面,但每当我尝试登录时,都会返回Seller_login.aspx
页面而不是{{1} }!我认为登录过程运行正常,因为我登录浏览器后问我是否要记住我的用户名和密码!但主页唯一的问题!请帮忙吗?
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