How to Redirect a person to a particular page after authentication

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="";
}
}
 
E

Edwin Knoppert

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

Karl Seguin

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="";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top