Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Forms authentication not working properly

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2006-11-11 : 13:15:27
My problem: the user logs on succeffuly, then he is redirected to ths first requested page, but when he clicks on another link on this latter, he s transfered back to the login page again (weird)
Here the authentication code THE LOGIN PAGE CLICK BUTTON

protected void Click_btnLogin(Object s, EventArgs e)
{
if(ValidateUser(txtUserName.Text, txtPassword.Text))
{
FormsAuthenticationTicket tkt;
string cookiestr;
HttpCookie ck;
tkt = new FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now,
DateTime.Now.AddSeconds(30), true, "your custom data");
cookiestr = FormsAuthentication.Encrypt(tkt);
ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
//if (chkPersistCookie.Checked)
ck.Expires=tkt.Expiration;
Response.Cookies.Add(ck);

string strRedirect;
strRedirect = Request["ReturnUrl"];
if (txtUserName.Text=="usr")
{strRedirect="dbaccess_interface/Results/results_page.aspx";}
else
{strRedirect = "dbaccess_interface/Results/results_page2.aspx";}
//else
//{
Response.Redirect(strRedirect , true);
//}

//HttpCookie coo=new HttpCookie("Preferences");
//FormsAuthentication.Authenticate(txtUserName.Text, txtPassword.Text);
//FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
}
//else
Response.Write("sorry");
//Response.Redirect("login.aspx");

}

Pls, ValidateUser checks just that the username and the password belong to the database which runs succefully since I get the first requested page successfully. But the problem happens with requesting the next page.
P.S: most of the code above is copied from msdn:Forms authentication

Thank you for your help.
   

- Advertisement -