<authentication mode="Forms">
<forms loginUrl="LoginPage.aspx"
protection="All"
timeout="1"
name=".ASPXAUTH"
path="/"
requireSSL="false"
slidingExpiration="false"
defaultUrl="HomePage.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false"/>
</authentication>
protected void btnSubmit_Click(object sender, EventArgs e)
{
int recordExistCount = fc.Authenticate(txtUsername.Text.Trim(), txtPassword.Text.Trim());
if (recordExistCount == 1)
{
Session["User"] = "Authenticated";
Session["Username"] = txtUsername.Text.Trim();
fc.IsOnlineRecord(Session["Username"].ToString(),true);
FormsAuthentication.RedirectFromLoginPage(Session["Username"].ToString(), true);
Response.Redirect("HomePage.aspx");
}
else
{
lblStatus.Text = "Username or password specified are incorrect";
lblStatus.BackColor = Color.Yellow;
}
}
Forms authentication doesnt work properly. After one successfull login , I go to the website url and it doesnt go to Homepage and instead takes me again to the loginpage.
What am I doing wrong?
It seems as though you are not setting the Formsauthentication. Therefore, in the code behind of the LoginPage.aspx – on the login click event try something like this