How to Redirect a person to a particular page after authentication

  • Thread starter Thread starter savvy
  • Start date Start date
S

savvy

I am using the code below to check whether a member is valid or not ,
and if he is then allowing him to certain parts of the site. My problem
is when a person logs on by entering his user ID and pwd he'll always
be directed to the index.aspx page.if he clicks APPLY JOB button it
should first ask for login details and then i want him to get directed
to the respective page (applyjob.aspx) not the index.aspx. I cant do
Response.Redirect then it will directly all my pages to the
applyjob.aspx. I hope i made some sense till now. Can anyone help me in
this pleas
Thanks in Advance
private void btnlogin_Click(object sender, System.EventArgs e)
{
bool blnAuthentication =
Authenticate(txtusername.Text,txtpassword.Text);
if(blnAuthentication)
{
FormsAuthentication.RedirectFromLoginPage(txtusername.Text,false);
Session["isMemberLoggedIn"]= true;
Response.Redirect("index.aspx");
}
else
{
Session["isMemberLoggedIn"]= false;
lblErr.Text = "Your Login was invalid. Please try again.";
txtusername.Text="";
}
}
 
I think you should remove:
FormsAuthentication.RedirectFromLoginPage(txtusername.Text,false);
 
Partially.

redirectFromLogin page does 2 things
(a) sets the authentication cookie
(b) redirects

You want to remove the call to RedirectFromLoginPage

but you must replace it with FormsAuthentication.SetAuthCookie and then you
can redirect as your example does.

Karl

P.S. - why use a session to track if the user is logged in if you are using
forms authentication?


--
MY ASP.Net tutorials
http://www.openmymind.net/


Edwin Knoppert said:
I think you should remove:
FormsAuthentication.RedirectFromLoginPage(txtusername.Text,false);


savvy said:
I am using the code below to check whether a member is valid or not ,
and if he is then allowing him to certain parts of the site. My problem
is when a person logs on by entering his user ID and pwd he'll always
be directed to the index.aspx page.if he clicks APPLY JOB button it
should first ask for login details and then i want him to get directed
to the respective page (applyjob.aspx) not the index.aspx. I cant do
Response.Redirect then it will directly all my pages to the
applyjob.aspx. I hope i made some sense till now. Can anyone help me in
this pleas
Thanks in Advance
private void btnlogin_Click(object sender, System.EventArgs e)
{
bool blnAuthentication =
Authenticate(txtusername.Text,txtpassword.Text);
if(blnAuthentication)
{
FormsAuthentication.RedirectFromLoginPage(txtusername.Text,false);
Session["isMemberLoggedIn"]= true;
Response.Redirect("index.aspx");
}
else
{
Session["isMemberLoggedIn"]= false;
lblErr.Text = "Your Login was invalid. Please try again.";
txtusername.Text="";
}
}
 
Back
Top