I'm working with ASP.Net application and I have followed this tutorial HERE to create a login page but whenever I tried to login it return to the Seller_login.aspx page not to Home.aspx page! I think the login process works fine because after I logged in the browser asked me if I want to remember my username and password! But the only problem with the home page! Please any help?
web.config code :
<authentication mode="Forms">
<forms defaultUrl="~/Home.aspx" loginUrl="~/Seller_Login.aspx" slidingExpiration="true" timeout="2880"></forms>
</authentication>
Seller_login.aspx.cs code:
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 code :
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
}
}