How to Redirect a person to a particular page after authentication

Discussion in 'ASP .Net' started by savvy, Nov 17, 2005.

  1. savvy

    savvy Guest

    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="";
    }
    }
    savvy, Nov 17, 2005
    #1
    1. Advertising

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


    "savvy" <> schreef in bericht
    news:...
    >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="";
    > }
    > }
    >
    Edwin Knoppert, Nov 17, 2005
    #2
    1. Advertising

  3. savvy

    Karl Seguin Guest

    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" <> wrote in message
    news:437cb09a$0$2334$...
    >
    > I think you should remove:
    > FormsAuthentication.RedirectFromLoginPage(txtusername.Text,false);
    >
    >
    > "savvy" <> schreef in bericht
    > news:...
    >>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="";
    >> }
    >> }
    >>

    >
    >
    Karl Seguin, Nov 17, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anita C
    Replies:
    3
    Views:
    717
    bruce barker
    Feb 21, 2004
  2. GS
    Replies:
    3
    Views:
    355
    Harlan Messinger
    Nov 14, 2006
  3. Replies:
    4
    Views:
    577
    Arne Vajhøj
    Nov 16, 2008
  4. Sal
    Replies:
    1
    Views:
    406
  5. GS
    Replies:
    1
    Views:
    98
    Randy Webb
    Nov 14, 2006
Loading...

Share This Page